简体   繁体   English

我的 SQL Workbench 无法将自动生成的 ID 插入表中

[英]My SQL Workbench Cannot insert an auto-generated id into table

`INSERT INTO terms (terms_id, terms_description, terms_due_days)
VALUES (AUTO_INCREMENT, 'Special terms', 90)`

I am trying to insert an auto generated id a term description and an int into an SQL table .我正在尝试将自动生成的 id、术语描述和 int 插入到 SQL 表中。 Run the query i get the error运行查询我得到错误

"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

So my question is how do I add a record of the next auto incremented number in the id array所以我的问题是如何在 id 数组中添加下一个自动递增数字的记录

Here is a snapshot of the db这是数据库的快照

数据库列

The expected usage of an auto increment column is to simply omit it from the insert, which will tell MySQL to auto generate the value:自动递增列的预期用法是简单地从插入中省略它,这将告诉 MySQL 自动生成值:

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

Create table using this query first.首先使用此查询创建表。

CREATE TABLE terms ( terms_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, terms_description VARCHAR(255) NOT NULL, terms_due_days int(5) NOT NULL );创建表条款(terms_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,terms_description VARCHAR(255) NOT NULL,terms_due_days int(5) NOT NULL );

Then Try insert然后尝试插入

INSERT INTO terms (terms_id, terms_description, terms_due_days) VALUES ( 'Special terms', 90)插入条款(terms_id、terms_description、terms_due_days)VALUES('特殊条款',90)

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

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