Mysql:在以下情况下使用:删除表,截断表,从表中删除 [英] Mysql: Which to use when: drop table, truncate table, delete from table

查看:88
本文介绍了Mysql:在以下情况下使用:删除表,截断表,从表中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列出以下MySql命令之间的区别.

List the differences between the following MySql commands.

  • 删除表表名;
  • 截断表表名;
  • 表名中删除,其中1;
  • drop table tablename;
  • truncate table tablename;
  • delete from tablename where 1;

也请根据您的经验告诉我每种产品的典型使用场景.

Also from your experiences please tell me typical usage scenario for each.

推荐答案

  • drop table tablename;
    • 在此之后,它消失了.没有桌子了.没有更多数据.
    • 当您不再需要该表时使用它.
      • drop table tablename;
        • After this, it's gone. No more table. No more data.
        • Use this when you don't need that table any more.
          • 此后,该表为空,并且(重要地)自动递增键被重置为1.这从字面上看就像是拥有一个全新的表.
          • 当您只需要一个空表时,请使用此选项.它比DELETE更快,因为它只是删除所有数据. DELETE将扫描表以生成受影响的行数.
          • After this, the table is empty, and (importantly) auto-incrementing keys are reset to 1. It's quite literally like having a brand new table.
          • Use this when you just want an empty table. It's faster than DELETE because it simply deletes all data. DELETE will scan the table to generate a count of rows that were affected.
          • 这使您可以基于可选的WHERE子句来筛选要删除的行.
          • 要删除特定记录时使用此记录,例如:DELETE FROM tablename WHERE username = 'joe'
          • This lets you filter which rows to delete based on an optional WHERE clause.
          • Use this when you want to delete specific records, eg: DELETE FROM tablename WHERE username = 'joe'

          这篇关于Mysql:在以下情况下使用:删除表,截断表,从表中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆