??????????t_topic????tid?2???????????“Java?????”???????????java???????????????????ww??
????????????????????е??????????????????????????
????????t_user??????uid??????У?
????CREATE TABLE t_user(
????uid INT PRIMARY KEY AUTO_INCREMENT??
????uname   VARCHAR(20) UNIQUE NOT NULL
????);
????????t_section??????sid??????У?u_id????t_user???uid?е??????
????CREATE TABLE t_section(
????sid INT PRIMARY KEY AUTO_INCREMENT??
????sname   VARCHAR(30)??
????u_id    INT??
????CONSTRAINT fk_t_user FOREIGN KEY(u_id) REFERENCES t_user(uid)
????);
???????t_section??????u_id????t_user???uid?е??????
????ALTER TABLE t_section
????ADD CONSTRAINT fk_t_user
????FOREIGN KEY(u_id)
????REFERENCES t_user(uid);
???????t_section??????u_id??????????
????ALTER TABLE t_section
????DROP FOREIGN KEY fk_t_user;
??????????????? 1??????
????????t_person???t_card??????????????????????????????????????????????????????????????????????????????????У????????????????????????????????????????????
??????t_card???????????У????t_user????????????????????? ??t_card?????????????????????t_user???????t_card???????????????
????????н??????????????????????????????????????????????????????
????create table husband(
????hid int PRIMARY KEY??
????...
????);
????create table wife(
????wid int PRIMARY KEY??
????...
????ADD CONSTRAINT fk_wife_wid FOREIGN KEY(wid) REFERENCES husband(hid)
????);
????????wife???wid?????????????????husband????????
????husband.hid?????????????????
????wife.wid??????????????????????????????????husband.hid??
?????????????wife??????????????wid?1?????wife???е??????????wid????????1????????????????
????????husband.hid?б??????1?????????wid???????????????????????
????2????????????
??????????????????????????????????????????ó??????t_user??t_section????????t_user??????????????t_section??????????????????????????????????????
????3??????
????????t_stu??t_teacher????????????????ж?????????????????????ж?????????????????????????м????????????????????????????t_stu_tea??????????????????????t_stu????????????????t_teacher????????
????????н????????????????м?????????????????м????????????????????????????????????????
????create table student(
????sid int PRIMARY KEY??
????...
????);
????create table teacher(
????tid int PRIMARY KEY??
????...
????);
????create table stu_tea(
????sid int??
????tid int??
????ADD CONSTRAINT fk_stu_tea_sid FOREIGN KEY(sid) REFERENCES student(sid)??
????ADD CONSTRAINT fk_stu_tea_tid FOREIGN KEY(tid) REFERENCES teacher(tid)
????);
?????????stu_tea????м???е????????????????student??teacher?????
??????????stu_tea???е?????sid?1001??tid?2001???????????1001??????????????2001?????
????sid    tid
????101    201 /*????101??????????????201?????*/
????101    202 /*????101??????????????202?????*/
????101    203 /*????101??????????????203?????*/
????102    201 /*????102??????????????201?????*/
????102    204 /*????102??????????????204?????*/