重置主键auto_increment [重复]

时间:2022-05-24 09:07:55

Possible Duplicate:
Reset primary key in mysql?

可能重复:在mysql中重置主键?

Is there any solution to when I

我什么时候有任何解决方案

delete from t1;

and then insert entities force the id to begin from id=1 again?

然后插入实体强制id再次从id = 1开始?

insert into t1 values(...);

2 个解决方案

#1


11  

[...] then insert entities force the id to begin from id=1 again?

[...]然后插入实体强制id再次从id = 1开始?

You can ALTER TABLE like this:

您可以像这样使用ALTER TABLE:

ALTER TABLE t1 AUTO_INCREMENT = 1;

Documentation here: MySQL ALTER TABLE Syntax

这里的文档:MySQL ALTER TABLE语法

#2


3  

Try truncate table http://dev.mysql.com/doc/refman/5.1/en/truncate-table.html

尝试截断表http://dev.mysql.com/doc/refman/5.1/en/truncate-table.html

This resets auto_increment columns back to 0.

这会将auto_increment列重置为0。

#1


11  

[...] then insert entities force the id to begin from id=1 again?

[...]然后插入实体强制id再次从id = 1开始?

You can ALTER TABLE like this:

您可以像这样使用ALTER TABLE:

ALTER TABLE t1 AUTO_INCREMENT = 1;

Documentation here: MySQL ALTER TABLE Syntax

这里的文档:MySQL ALTER TABLE语法

#2


3  

Try truncate table http://dev.mysql.com/doc/refman/5.1/en/truncate-table.html

尝试截断表http://dev.mysql.com/doc/refman/5.1/en/truncate-table.html

This resets auto_increment columns back to 0.

这会将auto_increment列重置为0。