这个SQL语句运行时出错
create table course(Cno char(4) primary key,Cname char(40),Cpno char(4),Ccredit smallint,foreign key Cpno references course(Cno));
出错信息为:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'references course(Cno))' at line 1
谁能给我解释一下?散分!
create table course(Cno char(4) primary key,Cname char(40),Cpno char(4),Ccredit smallint,foreign key Cpno references course(Cno));
出错信息为:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'references course(Cno))' at line 1
谁能给我解释一下?散分!
create table course(Cno char(4) primary key,Cname char(40),Cpno char(4),Ccredit smallint,foreign key (Cpno) references course(Cno));
create table SC(Sno char(9),Cno char(4),Grade smallint,primary key(Sno,Cno),foreign key (Sno) references student (Sno),foreign key (Cno) references course (Cno));
报错信息:
[Error Code: 1005, SQL State: HY000] Can't create table 'xufeipeng.sc' (errno: 150)
jan@hundin:~/trans/mysql-5.0/extra> perror 150
Error code 150: Unknown error 150
150 = Foreign key constraint is incorrectly formed。如果两个表student (Sno),course (Cno) 的对应字段都是not null,检查一下mysql的补丁更新。
foreign key (Cno) references course (Cno)这两个表 student , course 有没有建好?主键(sno) (cno)有指定?
确定外键引用的student (Sno),course (Cno)为主键
Cno char(4) primary key & Cpno char(4)???