mysql 事务怎么判断是否回滚
1个回答
展开全部
DELIMITER $$
BEGIN
DECLARE t_error INTEGER DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1 ;
START TRANSACTION;
UPDATE table1 SET a = '111';
INSERT INTO table2 (b) VALUES ('222');
INSERT INTO table3 (c) VALUES ('333');
IF t_error = 1 THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END$$
DELIMITER ;
BEGIN
DECLARE t_error INTEGER DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1 ;
START TRANSACTION;
UPDATE table1 SET a = '111';
INSERT INTO table2 (b) VALUES ('222');
INSERT INTO table3 (c) VALUES ('333');
IF t_error = 1 THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END$$
DELIMITER ;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询