[英]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 但是,如果将数据插入到此数据中,然后又将其删除(例如
regid=5
行),即使删除了5个,我的下一个输入也将具有regid值6。
这是auto_increment属性,因此它将从下一个开始,直到您截断表(从1开始)或通过按以下方式通过alter来设置选择auto_increment为止-
ALTER TABLE mytable AUTO_INCREMENT=6;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.