Often some perfectionists ask me, how to let the database's self-increment field in the record is deleted when the order to reset them, not to discuss whether such a toss is really necessary, just talk about the solution, there is a need for friends to see.
Method 1, delete the self-increment field, and then rebuild (the disadvantage is that you must remember other properties of the self-increment field, otherwise it may cause some unknown problems)
ALTER TABLE ' tablename ' DROP COLUMN ' id ';
ALTER TABLE ' tablename ' ADD ' id ' int (ten) unsigned not NULL auto_increment first,add PRIMARY KEY (' id '), auto_increment = 0 Row_format = COMPACT;
Method 2, through the SQL statements in order to reset the self-increment field values, the implementation method:
SET @i=0;
UPDATE ' tablename ' SET ' id ' = (@i:[email protected]+1);
ALTER TABLE ' tablename ' auto_increment=0
"MySQL" Two ways to make data table IDs contiguous