本文介绍了如何在MySQL中创建关系表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3张表,学生,课程,注册与<学生注册课程的关系
我已创建学生 > sid 为主键
我创建了课程 c> cid 作为主键
现在我必须创建 enroll 如下所示,但它在关键字引用上显示错误,错误是什么?
create table enroll( grade char(2), sid int not null, cid int not null,主键(sid,cid) 外键cid引用关于删除级联的课程,外键sid引用学生删除级联);解决方案
您必须指定要引用的字段外部表和两个关键字段集必须包括()。
外键(cid)引用删除级联上的课程(name_of_foreign_field_here), ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^
I have 3 tables, students, courses, enroll with relation as "students enroll in courses"
I have created students table with sid as primary key
I have created courses table with cid as primary key
Now I have to create enroll table which I did as follows, but it shows an error on the keyword references, what is the mistake ?
create table enroll( grade char(2), sid int not null, cid int not null, primary key(sid,cid), foreign key cid references courses on delete cascade, foreign key sid references students on delete cascade );解决方案
You have to specify which fields you're referencing in the foreign table, and both sets of key field(s) must be bracketed () as well.
foreign key (cid) references courses (name_of_foreign_field_here) on delete cascade, ^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
更多推荐
如何在MySQL中创建关系表?
发布评论