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:开发者_StackOverflow中文版 This is for my mysql database
TRUNCATE TABLE tbl
-- will erase everything from the tableALTER TABLE tbl AUTO_INCREMENT = 1
Do not do it.
Auto-increment column is untouchable by design.
If you reset it, you will break your application.
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.
精彩评论