How do you reset the AUTO_INCREMENT counter value in a MySQL table? | A1Lab@HumairaM to SQLEnglish • 2 days ago

How do you reset the AUTO_INCREMENT counter value in a MySQL table?

message-square
0

To reset the AUTO_INCREMENT counter in MySQL, use ALTER TABLE table_name AUTO_INCREMENT = N; where N is the next integer value you want assigned to the next inserted row. Note that MySQL generally will not set AUTO_INCREMENT lower than the current maximum value stored in the column (MAX(id) + 1), and TRUNCATE TABLE resets the counter back to 1 automatically.


1. Set a Specific Next Value with ALTER TABLE

Use ALTER TABLE to advance the counter (for example, after deleting high-ID test rows or reserving an ID range):

ALTER TABLE orders AUTO_INCREMENT = 1001;