Mysql存储过程中的事务回滚

create procedure test(in a int)
    BEGIN
        DECLARE t_error INTEGER DEFAULT 0;
        DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1;-- 异常时设置为1
        START TRANSACTION;
        INSERT into aaaa VALUES(2,3);
        INSERT into aaaaa VALUES(2,3);
        IF t_error = 1 THEN
            ROLLBACK;
        ELSE
            COMMIT;
        END IF;
    END

 

posted @ 2017-07-06 11:34  九人稚。  阅读(3924)  评论(0编辑  收藏  举报