gpt4 book ai didi

mySQL AUTO_INCREMENT 列创建

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:23 27 4
gpt4 key购买 nike

从昨天开始,我一直在尝试使用带有 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语句:

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

即使对于普通整数列,我也会收到此错误。我以前读过很多文章,据我所知,它应该以这种方式工作,没有任何问题。

谁能告诉我我做错了什么?

最佳答案

问题不是 AUTO_INCREMENT 而是它之前的 DEFAULT。没有为 DEFAULT 指定值。只需删除此处不需要的 DEFAULT 关键字即可。

另见 CREATE TABLE syntax在 MySQL 文档中,特别是:

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]

关于mySQL AUTO_INCREMENT 列创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37761938/

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