简体   繁体   English

mySQL AUTO_INCREMENT列创建

[英]mySQL AUTO_INCREMENT column creation

I'm trying to make simple database since yesterday with primary id key with AUTO_INCREMENT option but keep getting this error: 自昨天以来,我一直在尝试使用带有AUTO_INCREMENT选项的主ID密钥制作简单的数据库,但始终出现此错误:

Executing:
CREATE TABLE `spring`.`samochod` (
`idsamochod` INT NOT NULL DEFAULT AUTO_INCREMENT,
PRIMARY KEY (`idsamochod`));

Operation failed: There was an error while applying the SQL script to the database.
ERROR 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 'AUTO_INCREMENT,
PRIMARY KEY (`idsamochod`))' at line 2
SQL Statement:
CREATE TABLE `spring`.`samochod` (
  `idsamochod` INT NOT NULL DEFAULT AUTO_INCREMENT,
  PRIMARY KEY (`idsamochod`))

ERROR 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 'AUTO_INCREMENT,
PRIMARY KEY (`idsamochod`))' at line 2

SQL Statement: SQL语句:

CREATE TABLE `spring`.`samochod` (
  `idsamochod` INT NOT NULL DEFAULT AUTO_INCREMENT,
  PRIMARY KEY (`idsamochod`))

I am getting this error even for normal integer columns. 即使对于普通的整数列,我也会收到此错误。 I have read many articles before and as far as I understand it should work this way without any problems. 据我所知,我之前已经阅读了许多文章,并且应该可以毫无问题地以这种方式工作。

Could anyone tell me what I'm doing wrong? 谁能告诉我我在做什么错?

The problem is not the AUTO_INCREMENT but the DEFAULT before it. 问题不是AUTO_INCREMENT,而是之前的DEFAULT。 No value has been specified for DEFAULT. 没有为DEFAULT指定任何值。 Just remove the DEFAULT keyword which is not needed here. 只需删除此处不需要的DEFAULT关键字即可。

See also the CREATE TABLE syntax in the MySQL documentation, specifically: 另请参见MySQL文档中的CREATE TABLE语法 ,尤其是:

 column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] [COMMENT 'string'] [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}] [STORAGE {DISK|MEMORY|DEFAULT}] [reference_definition] 

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

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