这个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
谁能给我解释一下?散分!

解决方案 »

  1.   

    sql写错了,应该这么写吧:
    create table course(Cno char(4) primary key,Cname char(40),Cpno char(4),Ccredit smallint,foreign key (Cpno) references course(Cno)); 
      

  2.   

    那这个语句问题又在哪呢?帮忙看看
    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)
      

  3.   

    mysql的外建错误,
    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的补丁更新。
      

  4.   

    看看你的sno字段类型跟student表中sno字段类型是否相同。
      

  5.   

    查看关联的两列field typelengthdata 都有没有问题
      

  6.   

    foreign key (Sno) references student (Sno),
    foreign key (Cno) references course (Cno)这两个表 student , course 有没有建好?主键(sno) (cno)有指定?
      

  7.   


    确定外键引用的student (Sno),course (Cno)为主键
      

  8.   

    自己的列可以和自己的列关联主键关系???
    Cno char(4) primary key  &  Cpno char(4)???