Insert only in a table with one auto_increment column

it is possible to insert into a table with only one column, and this column is primary and auto_increment. exactly what I want is to increase id by one and write it to the table ... is it possible without specifying the maximum value and increase it by one, not by insertion. I think direct insertion just increases the value

+3
source share
2 answers

Yes: INSERT INTO foo (id) VALUES ('')

This will add a new entry and the identifier will automatically increment from 1 each time.
If this is useful, this is another question .. :-)

+3
source

, MySQL :

INSERT INTO Foo (id) VALUES (0);
INSERT INTO Foo (id) VALUES (''); -- because the integer value of '' is zero
INSERT INTO Foo (id) VALUES (NULL);
INSERT INTO Foo (id) VALUES (DEFAULT);
INSERT INTO Foo () VALUES ();
+5

Source: https://habr.com/ru/post/1767922/


All Articles