MySQL Delete all rows from table and reset ID to zero

后端 未结 5 1997
野性不改
野性不改 2020-12-12 09:29

I need to delete all rows from a table but when I add a new row, I want the primary key ID, which has an auto increment, to start again from 0 respectively from 1.

5条回答
  •  不思量自难忘°
    2020-12-12 09:50

    if you want to use truncate use this:

    SET FOREIGN_KEY_CHECKS = 0; 
    TRUNCATE table $table_name; 
    SET FOREIGN_KEY_CHECKS = 1;
    

提交回复
热议问题