MYSQL 中通过 savepoint 的方式来实现只提交事务的一部分。
step 1 : savepoint savepoint_name;、 做标记
step 2 :rollbak to savepoint savepoint_name;回滚到标记点
setp 3 :release savepoint savepoint_name;解除标记
----------------------------------------------------------------------------------------
例子:
create table T(X int,Y int); # 定义表
-------------------
delimiter //
create procedure proc_for_T_insert() # 在MYSQL中存储过程不管有没有参数,都要有(),SQL Server 中没有参数的存储过程一定不可以用();
begin
insert into T(X,Y) values(1,1);
savepoint savepoint_1; #step : 1、 做标记
insert into T(X,Y) values(2,2);
rollback to savepoint savepoint_1;#step : 2、回滚到标记点
release savepoint savepoint_1 #step : 3、解除标记
end //
delimiter ;
call proc_for_T_insert;
select * from T;