Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset primary key auto_increment [duplicate]

Tags:

mysql

Possible Duplicate:
Reset primary key in mysql?

Is there any solution to when I

delete from t1;

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

insert into t1 values(...);
like image 755
Nickool Avatar asked Jun 05 '11 08:06

Nickool


2 Answers

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

You can ALTER TABLE like this:

ALTER TABLE t1 AUTO_INCREMENT = 1;

Documentation here: MySQL ALTER TABLE Syntax

like image 125
aioobe Avatar answered Sep 20 '22 15:09

aioobe


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

This resets auto_increment columns back to 0.

like image 21
eroomydna Avatar answered Sep 24 '22 15:09

eroomydna