MySQL Forums
Forum List  »  Triggers

Re: Triggers can not use reference to tables?
Posted by: Jay Pipes
Date: June 28, 2005 09:31AM

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

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Triggers can not use reference to tables?
2649
June 28, 2005 09:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.