我找不到语法错误:
Drop Table if Exists Classes;
Drop Table if Exists Grades;
Drop Table if Exists Faculty;
Drop Table if Exists Students;
CREATE TABLE Faculty (StaffID INTEGER( 11 ),
StaffFirstName VARCHAR( 50 ),
StaffLastName VARCHAR( 50 ),
StaffPhone VARCHAR, CONSTRAINT PRIMARY KEY (StaffID) ) ENGINE = innodb;
CREATE TABLE Students (
StudentID INTEGER( 11 ) NOT NULL ,
StudentFirstName VARCHAR( 50 ) NOT NULL ,
StudentLastName VARCHAR( 50 ) NOT NULL ,
StudentPhone VARCHAR NOT NULL,
CONSTRAINT PRIMARY KEY (StudentID)
) ENGINE = innodb ;
CREATE TABLE Classes (
ClassID VARCHAR NOT NULL ,
ClassName VARCHAR( 50 ) NOT NULL ,
CONSTRAINT PRIMARY KEY (ClassID)
) ENGINE = innodb ;
CREATE TABLE Grades (
StaffID INTEGER( 11 ) NOT NULL ,
StudentID INTEGER( 11 ) NOT NULL ,
ClassID VARCHAR (11)NOT NULL ,
Grade VARCHAR( 2 ),
CONSTRAINT PRIMARY KEY (StaffID, StudentID, ClassID),
FOREIGN KEY (StaffID) references Faculty(StaffID),
FOREIGN KEY (StudentID) references Students(StudentID),
FOREIGN KEY (ClassID) references Classes(ClassID)
) ENGINE = innodb ;'
我试过取出空格和逗号并添加一些我无法找到的地方。这是错误:
CREATE TABLE Faculty (StaffID INTEGER( 11 ),
StaffFirstName VARCHAR( 50 ),
StaffLastName VARCHAR( 50 ),
StaffPhone VARCHAR, CONSTRAINT PRIMARY KEY (StaffID) ) ENGINE = innodb;
MySQL说:
文档#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在'附近使用。约束主要密钥(StaffID))ENGINE = innodb'在第4行
答案 0 :(得分:0)
我对MySql并不熟悉,但是有必要在Integer列中添加一个长度吗?你是说第一列的类型是
整数(11)