gpt4 book ai didi

mysql - 尝试创建表时出错

转载 作者:行者123 更新时间:2023-11-30 22:47:28 25 4
gpt4 key购买 nike

我找不到语法错误:

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 说:

Documentation #1064 - 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 ' CONSTRAINT PRIMARY KEY (StaffID) ) ENGINE = innodb' at line 4

最佳答案

我对MySql不是很熟悉,但是有必要给一个Integer列加一个长度吗?你是说第一列是类型

Integer (11)

关于mysql - 尝试创建表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29197726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com