简体   繁体   中英

how to alter an auto increment primary key in table in MySQL database?

I have a two tables,in which i have a table having a primary key given property auto increment .So if i alter the table by deleting a row and updated the table.But still the Key value is not changed.next input will be stored in consecutive value:

For eg

create table Student
(
regid int primary key auto_increment not null
)

regid here is the primary key,i also have a foreign key in another table. But if insert a data into this and later deleted it(say row where regid=5 ),my next input has a regid value 6 even if the 5 one is deleted.. Help me solve this

这是auto_increment属性,因此它将从下一个开始,直到您截断表(从1开始)或通过按以下方式通过alter来设置选择auto_increment为止-

ALTER TABLE mytable AUTO_INCREMENT=6;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM