MySQL

From blog.UsToBe.com

Jump to: navigation, search
| You are here: Home > Technology > MySQL

Contents

About

Frequently Asked Questions

How to reset an auto-increment value of a MySQL table

Just deleting all the rows in a table is not sufficient to reset the auto-increment value. When you add new rows, they will still be starting where the deleted ones left off.

Run this sql query to reset the autoincrement value:

TRUNCATE TABLE (table-name)

Of course TRUNCATE will also delete all your rows if you haven’t already. Not good if you don’t really want an empty table.

If you just want to change the auto_increment without deleting everything, you can run this query:

ALTER TABLE table-name AUTO_INCREMENT = new-value

External links

Personal tools