Skip to content

Instantly share code, notes, and snippets.

@EliuTimana
Created September 20, 2015 19:41
Show Gist options
  • Save EliuTimana/b5635cf76b39077980fb to your computer and use it in GitHub Desktop.
Save EliuTimana/b5635cf76b39077980fb to your computer and use it in GitHub Desktop.
DELIMITER $$
CREATE PROCEDURE sp_fail()
BEGIN
DECLARE _rollback BOOL DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET _rollback = 1;
START TRANSACTION;
INSERT INTO tablea (date) VALUES (NOW());
INSERT INTO tableb (date) VALUES (NOW());
INSERT INTO tablec (date) VALUES (NOW()); -- FAIL
IF _rollback THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment