我的代码有什么问题,因为没有错误,但是我无法运行它?

时间:2019-01-28 07:01:20

标签: mysqli

CREATE TABLE IF NOT EXISTS Grade (
StudentNumber VARCHAR(10) NOT NULL,
ClassNumber INT(10) NOT NULL,
Grade DOUBLE(3),
PRIMARY KEY(StudentNumber, ClassNumber),
FOREIGN KEY(StudentNumber)REFERENCES student(StudentNumber),
FOREIGN KEY(ClassNumber)REFERENCES class(ClassNumber)
)
  

MySQL说:文档

     

1064-您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以使用正确的语法   靠近'),PRIMARY KEY(StudentNumber,ClassNumber),FOREIGN   KEY(StudentNumber)REFERENC'在第4行

1 个答案:

答案 0 :(得分:2)

如果您使用double,则必须添加应包含的位数:

CREATE TABLE IF NOT EXISTS Grade (

StudentNumber VARCHAR(10) NOT NULL,

ClassNumber INT(10) NOT NULL,

Grade DOUBLE(3, 2),

PRIMARY KEY(StudentNumber, ClassNumber),

FOREIGN KEY(StudentNumber)REFERENCES student(StudentNumber),

FOREIGN KEY(ClassNumber)REFERENCES class(ClassNumber) )