MySQL changes the initial value of the primary key to 1

Problem description: For example, we have built a table in the database, the primary key id in the table is set to automatic growth type, due to one operation, we inserted some data into the table, but the data is wrong, so We need to delete these data, but we will find that the value of the primary key ID at this time is not 1, but the next digit of the sum of the previous data, so we need to set the primary key id to 1.

The table structure is as follows:

CREATE TABLE `user` (
  `id` double NOT NULL AUTO_INCREMENT,
  `tax_data` blob,
  `tax_vou_no` varchar(150) DEFAULT NULL,
  `tra_amt` decimal(20,0) DEFAULT NULL,
  `swtaxid` varchar(96) DEFAULT NULL,
  `cookie_name` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
); 

Solution:

ALTER TABLE `user` AUTO_INCREMENT=1;

In this case, the next time we insert data, its primary key id will start from 1.

Guess you like

Origin blog.csdn.net/y_bccl27/article/details/113919462