首页 > 数据库技术 > 详细

mysql存储过程事务

时间:2015-03-12 02:06:21      阅读:272      评论:0      收藏:0      [点我收藏+]
delimiter //
create procedure t_insert_table()  
begin  
    /** 标记是否出错 */  
    declare t_error int default 0;  
    /** 如果出现sql异常,则将t_error设置为1后继续执行后面的操作 */  
    declare continue handler for sqlexception set t_error=1; -- 出错处理  
    /** 显式的开启事务,它开启后,事务会暂时停止自动提交*/  
    -- start transaction;  
    /** 关闭事务的自动提交 */  
    set autocommit = 0;  
    insert into aaa value(1,2);
    insert into aaa value(1,2);
    insert into aaa value(3,4);  
    /** 标记被改变,表示事务应该回滚 */  
    if t_error=1 then  
        rollback; -- 事务回滚  
    else  
        commit; -- 事务提交  
    end if;  
end// 
delimiter ; 
 

?

mysql存储过程事务

原文:http://chendaiming.iteye.com/blog/2191627

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!