简体   繁体   中英

Auto_increment understanding

I have a database in phpmyadmin and there is one thing I don't understand with the auto_increment. I have several tables with each id auto_increment. If I remove a data with the id-number of 3 for example and then add a new data why does it print out id-number 4. I just deleted the id 3 shouldn't it print out id 3 again?

Preview

After each insert to the table, the autoincrement value is incremented by 1. So when you add row with ID 3, then autoincrement will be 4. Its not changed, when you delete some row(s).

To change autoincrement value (ID of the next inserted row), use this query:

ALTER TABLE table_name AUTO_INCREMENT = 3

Here is the documentation:

http://www.w3schools.com/sql/sql_autoincrement.asp

https://dev.mysql.com/doc/refman/5.6/en/example-auto-increment.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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