How can I make this field automatically increment from 1?

Whether the database table auto-increment field is emptied after a period of use, or continue to start from the emptied automatic number.
How can I make this field automatically increment from 1?

I have tried the following two methods, and they work well:

1 Clear all the data, remove the auto-increment, save it, add the auto-increment, save it, and start from 1
How to make the automatic numbering of mysql start from 1

2 truncate table your table name

This will not only clear the data, but also relocate the fields of the identity property

However, none of the above can preserve the existing data.

The following is to set MySQL automatic growth to start from a specified number 

1 When creating the table, set: 

CREATE TABLE `Test` (

`ID` int(11) NOT NULL AUTO_INCREMENT,

`class` varchar(2) NOT NULL,

`NAME` varchar(50) NOT NULL,

`SEX` varchar(2) NOT NULL,

PRIMARY KEY (`ID`)

) ENGINE=MEMORY AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC

 

2 If you don't set it when you create the table, and you want to set it later, you can implement it by modifying: 

alter table Test auto_increment = 1000; 

Guess you like

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