A
A
Apostrophe42019-07-15 20:59:48
MySQL
Apostrophe4, 2019-07-15 20:59:48

SQL "Help" INSERT INTO when adding ID with AUTO_INCREMENT?

You need to create a simple table.
Writing:

CREATE TABLE users (
   id INT AUTO_INCREMENT,
   PRIMARY KEY(id),
   names_list VARCHAR(60)
);

Next, using the command
DESC users;
I understand that the table is created with AUTO_INCREMENT.
Writing:
INSERT INTO users VALUES
('gfhjkl'),
('dfghjkl');

And it gives me an error. they ask to enter id, but my id is AUTO_INCREMENT. How can I enter data into a table without specifying an id?
While I use ALTER TABLE, but it is not a panacea.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Adamos, 2019-07-15
@Apostrophe4

INSERT INTO users(names_list) VALUES
Otherwise, SQL considers that the data is given for all columns, and 'gfhjkl' does not fit into id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question