我发现了一个mysql创建表语法错误,希望有人能在我失去理智之前发现它。
create table buyer_representations (
Key int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (Key)
);
错误1064(42000):您的SQL语法中有错误;查看与您的MySQL server版本相对应的手册,以了解在第2行“int not null auto_increment,Client_ID int not null,Start_Time varchar(5),star”附近使用的正确语法
mysql Ver 14.14 Distrib 5.7.29,适用于Linux(x86_64)使用EditLine包装器
我试着在第2行末尾添加“primary key”以及默认值,并将“not null”切换为“auto_increment”。但一切都不起作用。
编辑:我还尝试将Key更改为KeyId,并将Key放在引号中。但错误仍然不变。
编辑2:这里是我一直在尝试但没有成功的命令。错误总是相同的
create table buyer_representations (
`Key` int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (`Key`)
);
错误1064(42000):您的SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以了解在第2行“ int not null auto_increment,client_id int not null,start_time varchar(5)”附近使用的正确语法
create table buyer_representations (
KeyId int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (KeyId)
);
错误1064(42000):您的SQL语法中有错误;查看与您的MySQL server版本相对应的手册,以了解在第2行“not null auto_increment,client_id int not null,start_time varchar(5),start_”附近使用的正确语法
最终编辑(此操作有效):
感谢所有的帮助每个回答…我终于可以通过将Key放入双引号(单引号和后引号不起作用)来实现这个功能
create table buyer_representations (
“Key” int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (“Key”)
);
关键字是一个保留关键字,重命名它,你应该是黄金。
关键字和保留字的完整列表可以在第10.3节关键字和保留字中找到。下面
https://dev.mysql.com/doc/refman/8.0/en/keywords.html
在您的情况下,这应该起作用(我将其命名为test,但将其重命名为适合您的情况的任何名称)
create table buyer_representations (
test int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (test)
);
问题是您在表中使用的列名。第一个列名是key。Key在Mysql中被认为是一个保留词,它有着特殊的含义。这就是为什么会出现错误的原因。
如果要使用相同的列名,可以在``中写入列名。
为。创建表buyer_representations(`key`int not null auto_increment,
这会很好用的。