Sorry for the late reply...clients were calling (imagine that...)
DELIMITER //
CREATE TRIGGER DeleteDocument
AFTER DELETE ON _Documents
FOR EACH ROW
BEGIN
DELETE
FROM _RelatedDocs
WHERE _RelatedDocs.RelatedDocCode = OLD.DocCode;
END
//
BTW, Chagh, if this is what you are using triggers for, consider instead using a transaction-safe InnoDB table with binding foreign key constraints for the relationship between _Documents and _RelatedDocs. If the above tables are MyISAM , the trigger above is *NOT* transaction-safe even if used within a transaction. You can achieve a similar (and more efficient/stable) result by using InnoDB, having a FOREIGN KEY constraint, and using the ON DELETE CASCADE functionality.
Jay Pipes
Community Relations Manager, North America, MySQL Inc.
Got Cluster?
http://www.mysql.com/cluster
Personal:
http://jpipes.com