tags:

views:

30

answers:

1

I am experimenting with triggers for the first time.

When I try to create a trigger using the following:

CREATE TRIGGER t_foldersPrivate BEFORE DELETE ON foldersPrivate
FOR EACH ROW BEGIN
 DELETE FROM programs WHERE folderType = '0' AND folderID = OLD.ID; 
END;

I receive the following error:

`1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3`

(mysql 5.1.37)

If I get rid fo the delete statement the create trigger statement works fine. So I am assuming it must have something to do with that. But for the life of me I'm not sure what...

+1  A: 

You should change the delimiters.

Something like this:

DELIMITER $$

CREATE TRIGGER t_foldersPrivate BEFORE DELETE ON foldersPrivate
FOR EACH ROW BEGIN
 DELETE FROM programs WHERE folderType = '0' AND folderID = OLD.ID; 
END$$

DELIMITER ;

Also, you should check the delete query separately. Is it working?

santiagobasulto
Yes, the delete statement works fine separately.I tried using the above code, however it has the effect of crashing phpMyAdmin. The whole thing seized up until I restarted mysql...
Travis
I thing it's wrong to call "OLD.ID" in an "before" event. Thnik about it.Try doing this:DELETE FROM programs WHERE folderType = '0' AND folderID = ID;
santiagobasulto