tags:

views:

48

answers:

2

Is there a way to reset a table?

I mean not only deleting all rows, but starting the auto_incrementing ID back to 0?

+8  A: 

To remove all data:

TRUNCATE TABLE tablename

To reset the auto-increment:

ALTER TABLE tablename AUTO_INCREMENT = 1
RedFilter
As long as you're at v. 5.0.13 or later, the auto increment value is reset automatically by TRUNCATE TABLE. Prior to that it might be reset as long as there are no FKs into the truncated table (a "fast" truncate is used).
Tom H.
@Tom H. I am on 5.0.77 I just checked. So I just need to call the truncate line then. What are FKs?
John Isaacks
FK = foreign keys - which are references to the primary keys of other tables
CaseySoftware
+1  A: 

http://www.electrictoolbox.com/reset-auto-increment-value-mysql/

Brian
Embedded answers are preferred, as links may break.
quillbreaker