Jump to content

Reset ID Field


graham23s

Recommended Posts

SQL:

ALTER TABLE tablename AUTO_INCREMENT = 1

This will reset the next auto increment value to current largest value in the auto increment column + 1 (so executing this on an empty table will make the first id be 1 or whatever you specify)

 

Now to solve your problem, the easy is just DROP the auto_increment column and recreate it ;)

 

its a hack i guess but sure as hell beats doing it any other way...

 

EDIT: note you can also do this to force the next auto increment id to a certain value (not sure how this behaves if you specify a taken value, but im pretty sure it'll work like the above function and get the largest auto inc + 1

SET insert_id = 1;

Link to comment
https://forums.phpfreaks.com/topic/130620-reset-id-field/#findComment-677718
Share on other sites

EDIT: note you can also do this to force the next auto increment id to a certain value (not sure how this behaves if you specify a taken value, but im pretty sure it'll work like the above function and get the largest auto inc + 1

SET insert_id = 1;

I've never heard of that.

 

If you're starting again fresh, you can use TRUNCATE to empty the table properly, instead of DELETE.

Link to comment
https://forums.phpfreaks.com/topic/130620-reset-id-field/#findComment-678536
Share on other sites

EDIT: note you can also do this to force the next auto increment id to a certain value (not sure how this behaves if you specify a taken value, but im pretty sure it'll work like the above function and get the largest auto inc + 1

SET insert_id = 1;

I've never heard of that.

 

If you're starting again fresh, you can use TRUNCATE to empty the table properly, instead of DELETE.

 

that's the point:

 

delete only the id column, not the entire table!!  then re-create it as auto-inc (and possibly reset the counter by using ALTER TABLE) and it will assign new numbers.

 

and about "SET insert_id" look it up its in the manual :)

Link to comment
https://forums.phpfreaks.com/topic/130620-reset-id-field/#findComment-678883
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.