Reputation: 11
I am trying to create a trigger to delete articles after it deletes of all of its article contents. I am getting a 1064 error at line 5
.
Here is the PL/SQL I have written:
delimiter |
create trigger `cleanup_article` after delete on `article_content`
for each row
begin
declare x int;
set x = select count(*) as x from `article_content` where id = old.id;
if x = 0 then
delete from `article` where id=old.id;
end if;
end |
delimiter ;
Upvotes: 1
Views: 169
Reputation: 60262
There's a few problems there, due to invalid syntax for PL/SQL:
identifiers are either undelimited or delimited using ", not `
declare
must come before begin
set
is not a valid keyword. To get the count, use INTO
, e.g. SELECT COUNT(*) INTO x FROM ...
The DELETE statement refers to old.id
, this should be :old.id
What's with the "delimiter" statements? Just end the trigger definition with ;
Upvotes: 1