Reset autoincrement in mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
olifile
Forum Newbie
Posts: 6
Joined: Fri Aug 11, 2006 11:00 am

Reset autoincrement in mysql

Post by olifile »

Hi!!

I'm new user! :lol:

I have a problem in mysql. I dont know rest autoincrment in MYSQL.

Thank you for reply :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

ALTER TABLE `table` AUTO_INCREMENT =0
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Bear in mind that if you have data in your table and you reset the autoincremement pointer that you could run into all sorts of issues if that field is a primary key. I know from experience. It is a pain in the rear.
olifile
Forum Newbie
Posts: 6
Joined: Fri Aug 11, 2006 11:00 am

Post by olifile »

so simple 8O

Solved :wink:

tk you!!

:D :D
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I believe that:

TRUNCATE mytable;

Is the same as:

DELETE * FROM mytable;
ALTER TABLE `mytable` AUTO_INCREMENT =0;
(#10850)
Post Reply