MYSQL可否将外键设为主键?
这是SQLserver的,我想转换为MYSQL,请问如何转换?foreignkey(course_NO)referencescourse(course_NO),forei...
这是SQL server 的,我想转换为MYSQL,请问如何转换?
foreign key(course_NO) references course(course_NO),
foreign key(teacher_ID)references teacher (teacher_ID),primary key(course_NO,teacher_ID)); 展开
foreign key(course_NO) references course(course_NO),
foreign key(teacher_ID)references teacher (teacher_ID),primary key(course_NO,teacher_ID)); 展开
2个回答
展开全部
应该是可以的啊.
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)
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)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该可以的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询