I am trying to create a procedure that contains a transaction that has a rollback:
create or replace procedure move_animals(in diernaam varchar(25))
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING
START TRANSACTION;
BEGIN
ROLLBACK;
end;
insert into moved_animals(naam)
values(diernaam);
delete from animals
where naam in (diernaam);
COMMIT;
end;
call move_animals("giraf");
However, when I am doing an insert on table moved_animals
that isn't possible due to unique constraints it's still deleting that record from animal
. I would like to then rollback and undo the delete. What am I missing here?