MySQL Forums
Forum List  »  Newbie

Re: Resetting Auto Increment?
Posted by: Barry Galbraith
Date: August 22, 2012 08:59PM

You have fallen for the common misconception of what an auot-incerement is.
It's a means of providing a unique key for a row where no other "natural" unique key exists.
It's not for providing consecutive numbers. If you want those, then you will need to provide some other means of creating / allocating them.
If you empty a table, and want to set auto increment to 0, then TRUNCATE TABLE will empty the table of data, and set AUTO INCREMENT to 1.
If you just want to set AUTO INCREMENT to the max + 1 value in the table, then set it to 0 and it will find the max + 1 for you.
ALTER TABLE my_table AUTO_INCREMENT = 0;

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
August 22, 2012 08:32PM
Re: Resetting Auto Increment?
August 22, 2012 08:59PM
August 22, 2012 09:37PM
August 22, 2012 09:51PM
August 25, 2012 10:49AM
August 25, 2012 01:36PM
August 27, 2012 08:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.