tags:

views:

26

answers:

2

Hi, I have a field called IntQID, which is an id for each post that is recorded in the SQL database. If a post is 1533, the next entery will be 1534,1535, etc...

I recently messed up and inserted a manual entry with an ID of 4000. Now the counter has been using that as the last entry, so now new posted are 4001, 4002, 4003.

How do I change the counter to go back to using the next in line after 1533?

Hope this makes sense. Thanks!

+1  A: 

ALTER TABLE tbl AUTO_INCREMENT = 1000;

Scott Saunders
+1: This is valid, setting the auto_increment value is arbitrary. To me, anyways...
OMG Ponies
+3  A: 

To set the auto_increment value to 1533, use:

ALTER TABLE tbl AUTO_INCREMENT = 1533;

To my knowledge, you can't get the highest existing value for setting it in the ALTER TABLE statement without using two queries minimum.

OMG Ponies
So, I'd alter the whole table, not just a specific Field? My table name is tblQA and the field is IntQID, so ALTER TABLE tblQA AUTO_INCREMENT = 1533?
BigMike
@BigMike: This only affects the auto_increment field - doesn't matter what the name of the column is, because MySQL only allows one auto_increment column per table.
OMG Ponies
Perfect - works! Thanks everyone
BigMike