Mysql: Which to use when: drop table, truncate table, delete from table

前端 未结 5 1727
臣服心动
臣服心动 2020-12-14 10:59

List the differences between the following MySql commands.

  • drop table tablename;
  • truncate table tablename;
  • delete from
5条回答
  •  一向
    一向 (楼主)
    2020-12-14 11:34

    • Drop is deleting the table. I would drop the table if I didn't need it anymore
    • "Truncate operations drop and re-create the table, which is much faster than deleting rows one by one, particularly for large tables." - from MySQL manual
    • I would use delete to do a delete (of specific rows) with a query.

    I rarely "delete" anything from my databases. I generally put a flag column such as deleted as a boolean value. I check for that. If its true, I don't present that data.

提交回复
热议问题