user701510
user701510

Reputation: 5763

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

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

Answers (3)

Steven Feldman
Steven Feldman

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

zerkms
zerkms

Reputation: 254916

  1. TRUNCATE TABLE tbl -- will erase everything from the table
  2. ALTER TABLE tbl AUTO_INCREMENT = 1

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157839

Do not do it.
Auto-increment column is untouchable by design.

If you reset it, you will break your application.

Upvotes: 1

Related Questions