如何在MySQL数据库中修改表中的自动增量主键?

时间:2022-01-03 09:09:17

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

这里注册是主键,我在另一个表中也有一个外键。但是如果将数据插入到此后面并将其删除(比如regid = 5的行),我的下一个输入的注册值为6,即使删除了5个..帮我解决这个问题

1 个解决方案

#1


0  

This is the auto_increment property so it will start from next till either you truncate table (start from 1) or set your choice auto_increment by alter as per below-

这是auto_increment属性,因此它将从下一个开始直到你截断表(从1开始)或通过alter设置你的选择auto_increment,如下所示 -

ALTER TABLE mytable AUTO_INCREMENT=6;

#1


0  

This is the auto_increment property so it will start from next till either you truncate table (start from 1) or set your choice auto_increment by alter as per below-

这是auto_increment属性,因此它将从下一个开始直到你截断表(从1开始)或通过alter设置你的选择auto_increment,如下所示 -

ALTER TABLE mytable AUTO_INCREMENT=6;