Search code examples
mysqlmysql-workbenchprimary-keymysql-error-1064

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 . 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

Here is a snapshot of the db

databaseCol


Solution

  • 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:

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