简体   繁体   English

创建表时出现MySQL错误1064(42000)

[英]MySQL ERROR 1064 (42000) when creating a table

I've looked at previous posts but I am struggling to figure out where i am going wrong. 我看过以前的帖子,但我一直在努力找出我要去哪里。 I am trying to create a table using this code: 我正在尝试使用此代码创建表:

mysql> CREATE TABLE Engine
-> (
-> ID VARCHAR(255) UNASSSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
-> Name VARCHAR(255) NOT NULL,
-> Displacement VARCHAR(10) NOT NULL,
-> Code VARCHAR(10) NOT NULL,
-> PowerOutput VARCHAR(10),
-> MadeAt VARCHAR(255) NOT NULL,
-> PRIMARY KEY (ID),
-> FOREIGN KEY (MadeAt)
-> );

However I am repeatedly getting this error: 但是,我反复收到此错误:

ERROR 1064 (42000): 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 'UNASSSIGNED NOT NULL AUTO_INCREMENT UNIQUE,

Name VARCHAR(255) NOT NULL, Displace' at line 3 在第3行名称VARCHAR(255)NOT NULL,Displace'

Any help would be much appreciated. 任何帮助将非常感激。

Try to change 尝试改变

ID VARCHAR(255) UNASSSIGNED NOT NULL AUTO_INCREMENT UNIQUE

into: 变成:

ID INT NOT NULL AUTO_INCREMENT

UNASSIGNED should be UNSIGNED , but it is not necessary to define this, because AUTO_INCREMENT will start at 1 by default when not defined otherwise. UNASSIGNED应该为UNSIGNED ,但是没有必要定义它,因为默认情况下,否则将定义AUTO_INCREMENT1开始。 UNIQUE is redundant as well, because the ID will increment and the numbers will be unique anyway. UNIQUE也是多余的,因为ID会递增,而数字无论如何都是唯一的。

In most cases VARCHAR is not recommended to use as PRIMARY KEY . 在大多数情况下,不建议将VARCHAR用作PRIMARY KEY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM