ROLLBACK TO [SAVEPOINT]> 与SAVEPOINT命令一起使用,可以把事务回滚到标记点,而不会滚在此标记点之前的任何工作。
设置事务隔离级别
SET TRANSACTION
INNODB存储引擎提供的事务隔离级别READ UNCOMMITTED、READ COMMITTED、REPEATABLE READ和SERIALIZABLLE ①在存储过程中,mysql数据库的分析器会自动将BEGIN识别为BEGIN...END,因此在存储过程中只能使用START TRANSACTION语句来开启一个事务。 ②COMMIT和COMMIT WORK语句基本上是一致的。不同之处在于COMMIT WORK用来控制事务结束后的行为是CHAIN还是RELEASE。 Value Description NO_CHAIN(or 0) COMMIT and ROLLBACK are unaffected. This is the default value. CHAIN (or 1) COMMIT and ROLLBACK are equivalent to COMMIT AND CHAIN and ROLLBACK AND CHAIN, respectively. (A new transaction starts immediately with the same isolation level as the just-terminated transaction.) RELEASE(or 2) COMMIT and ROLLBACK are equivalent to COMMIT> and ROLLBACK>, respectively. (The server disconnects after terminating the transaction.)
(1)set completion_type=0
可以通过参数completion_type来进行控制,default为0或NO_CHAIN,表示没有任何操作。
mysql>show variables like 'completion_type';
+-----------------+----------+
|Variable_name | Value |
+-----------------+----------+
|completion_type | NO_CHAIN |
+-----------------+----------+
1 row inset (0.00 sec)
(2)set completion_type=1
mysql> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
1 row in set (0.00 sec)
创建表test
droptable if exists t;
create tablet(id int primary key)engine=innodb;
setcompletion_type=1;
begin;
insertinto t select 1;
commitwork;
insertinto t select 2;
insertinto t select 2;
ERROR1062 (23000): Duplicate entry '2' for key 'PRIMARY'
mysql>rollback;
Query OK,0 rows affected (0.00 sec)
mysql>select * from t;
+----+