How mysql reorders auto-increment id from 1

Method 1: If the previous data is not needed, you can directly clear all the data, and restore the auto-increment field to count from 1

truncate table  table name

 

Method Two:

dbcccheckident ('table_name', reseed, new_reseed_value)

The current value is set to new_reseed_value. If no rows have been inserted into the table since the table was created, the first row inserted after a DBCC CHECKIDENT will use new_reseed_value as the identity. Otherwise, the next inserted row will use  new_reseed_value + 1. If the value of new_reseed_value is less than the maximum value in the identity column, error message No. 2627 will be generated when referring to the table later.

 

The second method does not clear the existing data, and the operation is more flexible. It can not only reset the self-increment to zero, but also apply to reset the self-increment and insert new data after deleting a large number of consecutive rows; or start from a new value. some conflict.

 

Transfer: http://blog.csdn.net/u012964999/article/details/51742475

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326394584&siteId=291194637