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

前端 未结 5 1736
臣服心动
臣服心动 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:17

    Delete

    • DELETE statement deletes table rows and returns number of rows deleted

    Truncate

    • TRUNCATE drops the table and re-create it. It is much faster than deleting rows one by one.
    • TRUNCATE removes all the rows from the Table.
    • TRUNCATE does not return number of deleted rows.

    Drop

    • deletes the data as well as structure.
    • The difference between DROP and DELETE table is that, after executing DELETE statement the contents of table are removed but the structure remains same, but in case of DROP statement both the contents and structure are removed.

提交回复
热议问题