MySQL Forums
Forum List  »  Triggers

Re: How i can reject a row in a trigger?
Posted by: Bob Field
Date: January 11, 2007 04:44PM

The solution I have worked out to abort a deletion via a before delete trigger is this:
DELIMITER $$
CREATE TRIGGER triggername BEFORE DELETE ON yourtable
FOR EACH ROW
BEGIN
  DECLARE temp int;
  SELECT `DELETE aborted` INTO temp FROM yourtable;
END$$
DELIMITER ;
This should abort the delete and leave the row(s) intact. Selecting a non-existent column name works to raise an error in triggers and stored routines. The bad column name can double as your error message. You can wrap whatever conditional you want around the SELECT statement.

Options: ReplyQuote


Subject
Views
Written By
Posted
5606
January 11, 2007 09:51AM
2231
January 11, 2007 09:57AM
2139
January 11, 2007 12:06PM
Re: How i can reject a row in a trigger?
2267
January 11, 2007 04:44PM


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.