首页 > 代码库 > truncate和delete对于回滚的区别
truncate和delete对于回滚的区别
(1)delete在事务中可以回滚
mysql>select * from t;
+----+
| id |
+----+
| 1 |
| 2 |
+----+
2 rows inset (0.00 sec)
mysql>begin;
Query OK,0 rows affected (0.00 sec)
mysql>delete from t where id=2;
Query OK,1 row affected (0.04 sec)
mysql>select * from t;
+----+
| id |
+----+
| 1 |
+----+
1 row inset (0.00 sec)
mysql>rollback;
Query OK,0 rows affected (0.01 sec)
mysql>select * from t;
+----+
| id |
+----+
| 1 |
| 2 |
+----+
2 rows inset (0.00 sec)
(2)truncate在事务中不能回滚
mysql>begin;
Query OK,0 rows affected (0.00 sec)
mysql>truncate table t;
Query OK,0 rows affected (0.03 sec)
mysql>rollback;
Query OK,0 rows affected (0.00 sec)
mysql>select * from t;
Empty set(0.00 sec)
mysql>
truncate和delete对于回滚的区别
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。