简体   繁体   English

创建MySql表时出错

[英]Error while creating a MySql table

I am trying to create a table from my command line ( Debian ), but it keeps saying I have an error in my syntax. 我正在尝试从命令行( Debian )创建一个表,但是它一直说我的语法有错误。 To me it looks fine and I have got it checked by 2 different people who also cannot find the issue. 对我来说,它看起来还不错,我已经由2个不同的人进行了检查,他们也都找不到问题。

CREATE TABLE users (
   id INT(6) UNSIGNED AUTO_INCREMENT, 
   uuid VARCHAR(32) NOT NULL, 
   key VARCHAR(50) NOT NULL
);

One guy said remove NOT NULL but I still had the same issue. 一个人说删除NOT NULL,但是我仍然遇到同样的问题。

KEY is a reserved word try change with my_key KEY是保留字,请尝试使用my_key进行更改

 CREATE TABLE users (id INT( 6) UNSIGNED AUTO_INCREMENT, 
      uuid VARCHAR(32) NOT NULL, 
     my_key VARCHAR(50) NOT NULL,
     PRIMARY KEY (`id`));

Sorry, 抱歉,

for an AUTO_INCREMENT Field you MUST have a key on this COLUMN. 对于AUTO_INCREMENT字段,您必须在此COLUMN上有一个键。

So this works: 所以这有效:

CREATE TABLE `user` (
  `id` int(6) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(32) DEFAULT NULL,
  `key` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

MySQL has lots of reserved keywords that cannot be used as column names. MySQL有许多不能用作列名的保留关键字。 Here you are using key as a column name, and since it is a reserved keyword in MySQL, you need to change the name of the column to something that is not a reserved keyword. 在这里,您使用key作为列名,并且由于它是MySQL中的保留关键字,因此您需要将列名更改为非保留关键字。

You can find a full list of reserved keywords that cannot be used as a column name here . 您可以在此处找到不能用作列名的保留关键字的完整列表。

The column name "key" you used for the third column is a reserved word, all you have to do is change the name. 您在第三列中使用的列名“键”是保留字,您所要做的就是更改名称。

Well, one probably can't know all the existing keywords in a programming language but one can help himself/herself by using colour-code enabled text editor or Integrated Development Environment (IDE) when writing codes. 好吧,一个人可能不了解一种编程语言中的所有现有关键字,但是在编写代码时,可以使用启用了颜色代码的文本编辑器或集成开发环境(IDE)来帮助自己。 It helps a lot. 这很有帮助。

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

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