在MySQL中,我们可以禁用自动提交功能,因此语句必须显式地提交到数据库,这是(应该)好的,因为如果我们搞砸了什么,我们可以回滚(撤消)操作。
这就是我面临的问题,删除的表不能回滚(意味着表已经永远消失了)
我的问题是,到底什么样的语句可以回滚?
mysql> SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
1 row in set (0.00 sec)
mysql> SET @@autocommit = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 0 | // autocommit disabled
+--------------+
1 row in set (0.00 sec)
mysql> DROP TABLE testTable; // deleting the testTable
Query OK, 0 rows affected (0.02 sec)
mysql> ROLLBACK; // rollback commit
Query OK, 0 rows affected (0.00 sec)
mysql> TABLE testTable; // testTable deleted (DROP TABLE statement is not rolled back)
ERROR 1146 (42S02): Table 'testDB.testTable' doesn't exist
mysql> 发布于 2020-09-26 17:04:32
MySQL documents Statements That Cause an Implicit Commit。通常,这些包括定义或修改数据库对象的任何内容(表、函数、触发器、视图、索引……任何带有create语句的语句),如create <thing>、alter <thing>和drop <thing>。
https://stackoverflow.com/questions/64075613
复制相似问题