zoukankan      html  css  js  c++  java
  • mysql5.1中delete和truncate的区别,实例如下

    create table test_del(id int auto_increment,name varchar(10),primary key(id));
    insert into test_del(name) values('xuhao'),('fdsa'),('fddsf');
    create table test_truc(id int auto_increment,name varchar(10),primary key(id));
    insert into test_truc(name) values('xuhao'),('fdsa'),('fddsf');

    mysql> select * from test_del; +----+-------+ | id | name | +----+-------+ | 1 | xuhao | | 2 | fdsa | | 3 | fddsf | +----+-------+ 3 rows in set mysql> select * from test_truc; +----+-------+ | id | name | +----+-------+ | 1 | xuhao | | 2 | fdsa | | 3 | fddsf | +----+-------+ 3 rows in set mysql> delete from test_del; Query OK, 3 rows affected mysql> delete from test_truc where true; Query OK, 3 rows affected mysql> insert into test_del(name) values('xuhao'),('fdsa'),('fddsf'); Query OK, 3 rows affected Records: 3 Duplicates: 0 Warnings: 0 mysql> insert into test_truc(name) values('xuhao'),('fdsa'),('fddsf'); Query OK, 3 rows affected Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from test_del; +----+-------+ | id | name | +----+-------+ | 4 | xuhao | | 5 | fdsa | | 6 | fddsf | +----+-------+ 3 rows in set mysql> select * from test_truc; +----+-------+ | id | name | +----+-------+ | 4 | xuhao | | 5 | fdsa | | 6 | fddsf | +----+-------+ 3 rows in set mysql> truncate test_truc; Query OK, 0 rows affected mysql> insert into test_truc(name) values('xuhao'),('fdsa'),('fddsf'); Query OK, 3 rows affected Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from test_truc; +----+-------+ | id | name | +----+-------+ | 1 | xuhao | | 2 | fdsa | | 3 | fddsf | +----+-------+ 3 rows in set

    对于表中的自增id,delete和truncate的处理方式是不同,另外据说delete操作会写入日志,truncate不写入日志,言下之意,truncate慎用,不易恢复。

  • 相关阅读:
    Ansible主机信息模块 setup
    Ansible命令模块(unarchive模块 archive模块 )
    Ansible命令模块(mount模块 selinux模块 firewalld模块 )
    Ansible命令模块(group模块 user模块 cron模块 )
    Ansible命令模块(get_url 模块 service模块 systemd模块 )
    Ansible命令模块(yum模块 copy模块 file模块 )
    Ansible命令模块(command模块 shell模块 script模块 )
    Ansible 的 ad-hoc
    Ansible配置主机清单
    每日总结3.30
  • 原文地址:https://www.cnblogs.com/rabbit168/p/4225905.html
Copyright © 2011-2022 走看看