1. 程式人生 > >mysql多對多的關係如何表示(主鍵也可做外來鍵)

mysql多對多的關係如何表示(主鍵也可做外來鍵)

mysql> CREATE TABLE course (
-> course_NO INT PRIMARY KEY
-> );
Query OK, 0 rows affected (0.19 sec)

mysql>
mysql> CREATE TABLE teacher (
-> teacher_ID INT PRIMARY KEY
-> );
Query OK, 0 rows affected (0.08 sec)

mysql> CREATE TABLE temp (
-> course_NO INT,
-> teacher_ID INT,
-> foreign key(course_NO) references course(course_NO),
-> foreign key(teacher_ID)references teacher (teacher_ID),
-> primary key(course_NO,teacher_ID)
-> );
Query OK, 0 rows affected (0.10 sec)