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 cou开发者_StackOverflownt(*) as x from `article_content` where id = old.id;
if x = 0 then
delete from `article` where id=old.id;
end if;
end |
delimiter ;
There's a few problems there, due to invalid syntax for PL/SQL:
identifiers are either undelimited or delimited using ", not `
declare
must come beforebegin
set
is not a valid keyword. To get the count, useINTO
, 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
;
精彩评论