This article introduces two methods for sorting auto-incremental IDs from 1 in mysql, which reduces the workload of initializing data for a project, if you are interested, you may find it a headache to initialize data for the current project recently. In addition, the auto-increment of database IDs is getting bigger and bigger, so you need to repeat auto-increment from 1: use the following method:
Method 1:If no data is needed, you can directly clear all the data and restore the auto-increment field to count from 1.
Truncate table name
Method 2:The current value of dbcc checkident ('Table _ name', reseed, new_reseed_value) is set to new_reseed_value. If the row is not inserted into the table after the table is created, new_reseed_value is used as the ID of the first row inserted after dbcc checkident is executed. Otherwise, new_reseed_value + 1 is used for the next inserted row. If the value of new_reseed_value is smaller than the maximum value in the ID column, error 2627 will be generated when the table is referenced later.
Method 2 does not clear existing data, and the operation is flexible. it can not only return the auto-increment value to zero, but also apply to deleting a large number of consecutive rows, resetting the auto-increment value and inserting new data; or starting from a new value, of course, it cannot conflict with an existing one.
$ SQL = "delete from $ table_vote ";
Mysql_query ($ SQL, $ link );
$ SQL = "alter table $ table_vote auto_increment = 1 ";
Mysql_query ($ SQL, $ link );
The above is all the content of this article. I hope these two methods will be helpful for your learning.