The method of rearranging id by mysql
Editor to share with you how mysql rearranges the id, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article, so let's learn about it!
The method that mysql rearranges id: 1, use column count [alter table tablename drop column id]; 2, use increment to arrange [alter table tablenam auto_increment].
How mysql rearranges id:
When using mysql, there is usually a self-increasing id field in the table, but when we want to empty the data in the table and re-add data, we want id to start counting again from 1, either of the following two methods:
Method 1:
Alter table tablename drop column id;alter table tablename add id mediumint (8) not null primary key auto_increment first
Method 2:
Alter table tablename auto_increment=0
Method 2 will not clear the existing data, and the operation is more flexible, which can not only return 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 with a new value, of course, it can not conflict with the existing ones.
$sql= "delete from $table_vote"; mysql_query ($sql, $link); $sql= "alter table $table_vote auto_increment=1"; mysql_query ($sql, $link); these are all the contents of mysql's method of rearranging id. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!