create trigger check_td before
for each row begin
declare v_code_ID varchar(25);
declare c_Worker1 cursor for select code_ID from Worker1;
declare c_Worker2 cursor for select code_ID from Worker2;
if inserting or updating Worker1 then
open c_Worker2;
fetch c_Worker2 into v_code_ID;
while c_Worker2%found loop
if v_code_ID = :new.code_ID then
SIGNAL SQLSTATE '-1'
SET MESSAGE_TEXT = 'Error A.';
end if;
fetch c_Worker2 into v_code_ID;
end loop;
close c_Worker2;
end if;
if inserting or updating Worker2 then
open c_Worker1;
fetch c_Worker1 into v_code_ID;
while c_Worker1%found loop
if v_code_ID = :new.code_ID then
SIGNAL SQLSTATE '-1'
SET MESSAGE_TEXT = 'Error B.';
end if;
fetch c_Worker1 into v_code_ID;
end loop;
close c_Worker1;
end if;
end;
I come from Oracle databases and I'm trying to get this MySQL Trigger working. The error says that the problem is in the 4th line (or around) but after searching, I found that this way is the correct way to declare varchar variables in MySQL.
Can somebody give me a hand? It's slightly difficult because some syntax changes a bit.
Thank you very much, any help is appreciated.