【问题标题】:My SQL Workbench Cannot insert an auto-generated id into table我的 SQL Workbench 无法将自动生成的 id 插入表中
【发布时间】:2020-04-03 05:58:08
【问题描述】:
`INSERT INTO terms (terms_id, terms_description, terms_due_days)
VALUES (AUTO_INCREMENT, 'Special terms', 90)`

我正在尝试将自动生成的 id、术语描述和 int 插入 SQL 表中。 运行查询我得到错误

"00:01:57   INSERT INTO terms (terms_id, terms_description, terms_due_days) VALUES (AUTO_INCREMENT, 'Special terms', 90)    Error Code: 1054. Unknown column 'AUTO_INCREMENT' in 'field list'   0.000 sec

所以我的问题是如何在 id 数组中添加下一个自动递增数字的记录

这是数据库的快照

【问题讨论】:

标签: mysql mysql-workbench primary-key mysql-error-1064


【解决方案1】:

自增列的预期用法是在插入时简单地省略它,这将告诉 MySQL 自动生成值:

INSERT INTO terms (terms_description, terms_due_days)
VALUES ('Special terms', 90);

【讨论】:

    【解决方案2】:

    首先使用此查询创建表。

    CREATE TABLE 术语 ( terms_id INT(6) 未签名的 AUTO_INCREMENT 主键, terms_description VARCHAR(255) 非空, terms_due_days int(5) 非空 );

    然后尝试插入

    INSERT INTO 条款(terms_id、terms_description、terms_due_days)VALUES ('Special 条款',90)

    【讨论】:

      猜你喜欢
      • 2016-10-22
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多