How to reset a mysql primary key

Sometimes you want to reset your auto_increment primary key in mysql so that the newly inserted records start at 1. In my testing database, for convenience, I want to do this (never mind why. Just live with it. Any smug comments about depending on fixed primary key values are noted, so no need to add them. Unless you're a dick).

Resetting the primary key is straightforward:

alter table foo AUTO_INCREMENT = 1

No comments:

Post a Comment