Adding rows to a table with identity column
page 4
How to reset auto increment values to avoid gaps (MySQL)?
Let's take the table considered on the previous page and insert into it 3 rows.
CREATETABLE test_Identity (
id int(11)NOTNULLAUTO_INCREMENT,
PRIMARYKEY(id)
);
INSERTINTO test_Identity VALUES(),(),();
SELECT * FROM test_Identity;
id
1
2
3
If we shall delete the last row, numbering will proceed not with 3, but with 4. I.e. last value of the counter is kept and used at the subsequent addition of rows:
DELETEFROM test_Identity WHERE id=3;
INSERTINTO test_Identity VALUES();
SELECT * FROM test_Identity;
id
1
2
4
There is a question: " Whether is it possible to make numbering proceeding from last available value? " Apart from a question about what it is necessary for, the answer is - possible. But this value of the counter should be set manually. So,