开发者

How to clear data from a certain column without deleting it in mysql

开发者 https://www.devze.com 2023-02-24 22:37 出处:网络
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.

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


  1. TRUNCATE TABLE tbl -- will erase everything from the table
  2. ALTER 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消