MySQL Forums
Forum List  »  Triggers

Re: Duplicated values
Posted by: Bill Karwin
Date: June 27, 2006 10:29AM

There's no exception feature in triggers. The only thing you can do to force an error reliably is to define one of those columns as NOT NULL, and set the column to NULL if the "before" trigger finds a condition it doesn't like.

DELIMITER //
CREATE TRIGGER no_like_equal_numbers BEFORE INSERT ON Curses
FOR EACH ROW
BEGIN
IF NEW.column3 = NEW.column4 THEN
SET NEW.column3 = NULL;
END IF
END; //
DELIMITER ;

column3 should be defined NOT NULL, so the trigger above will cause the statement to fail if 1 = 1 as in your example.

Regards,
Bill K.

Options: ReplyQuote


Subject
Views
Written By
Posted
2655
June 27, 2006 09:08AM
Re: Duplicated values
1783
June 27, 2006 10:29AM


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.