Delete, Truncate or Drop to clean out a table in MySQL

前端 未结 6 624
野性不改
野性不改 2021-02-07 03:49

I am attempting to clean out a table but not get rid of the actual structure of the table. I have an id column that is auto-incrementing; I don\'t need to keep the

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 04:11

       Drop will do just that....drop the table in question, unless the table is a parent to another table.

       Delete will remove all the data that meets the condition; if no condition is specified, it'll remove all the data in the table.
       Truncate is similar to delete; however, it resets the auto_increment counter back to 1 (or the initial starting value). However, it's better to use truncate over delete because delete removes the data by each row, thus having a performance hit than truncate. However, truncate will not work on InnoDB tables where referential integrity is enforced unless it is turned off before the truncate command is issued.
       So, relax; unless you issue a drop command on the table, it won't be dropped.

提交回复
热议问题