DelphiFAQ Home Search:

How to change the next value of an auto_increment field

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

I have a table where the primary key is an auto increment field. I just deleted the last 2 rows and when the next record will be created it will use the next higher number but I'd like to subtract 2 from the auto_increment value. How can I do this?

Answer:

Use the ALTER TABLE statement as shown below:

/* this makes the next record have 911 in the auto increment field: */
alter table MYTABLE auto_increment=911;

Content-type: text/html

Comments:

2013-11-19, 17:14:18
MK from Poland  
I see the same answer all over the Internet, how come this doea not work on my machine? All I am getting is 'Query OK, 0 rows affected' and that's it, the auto_increment value remains unchanged.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: