Home > Database > Mysql Tutorial > body text

How to reset the initial value of the auto-increment column in the table in MySQL and share the implementation method

黄舟
Release: 2017-03-24 13:21:41
Original
1624 people have browsed it

This article mainly introduces the relevant information on the implementation method of resetting the initial value of the auto-increment column in the table in MySQL. Friends in need can refer to the following

How to implement the initial value of the auto-increment column in the table in MySQL

1. Question raised

In the database design of MySQL, it is generally designed An auto-incrementing numeric column used as a business-independent primary key. After frequent deletion or clearing operations in the database, its self-increasing value will still increase automatically. What should I do if I need to start over?

2. Solution

a. alter table

delete from table_name; 
ALTER TABLE table_name AUTO_INCREMENT = 1;
Copy after login

If there is a lot of data in the database table, the deletion operation will last for a long time. This Issues require attention.

b. truncate

truncate table_name
Copy after login

Simple and fast, clear the data directly.

3. Delete vs tuncate

The main differences are as follows:

  • Truncate is fast and does not log record, so the rollback operation cannot be performed. delete and vice versa.

  • truncate will reset the index and auto-increment the initial value, delete will not

  • truncate will not trigger the trigger, but delete will. .

The above is the detailed content of How to reset the initial value of the auto-increment column in the table in MySQL and share the implementation method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!