Reputation: 5763
How do I clear data from a column and then set the first value as 1 with auto increment? I do not want to delete the column, merely to reset it.
edit: This is for my mysql database
Upvotes: 0
Views: 2249
Reputation: 841
UPDATE TABLE SET col=0;
UPDATE Table AS T1 SET T1.col=1+ (SELECT MAX(T2.COL) FROM TABLE AS T2)
That should do it.
Upvotes: -1
Reputation: 254916
TRUNCATE TABLE tbl
-- will erase everything from the tableALTER TABLE tbl AUTO_INCREMENT = 1
Upvotes: 1
Reputation: 157839
Do not do it.
Auto-increment column is untouchable by design.
If you reset it, you will break your application.
Upvotes: 1