MySQL Forums
Forum List  »  Triggers

trigger Throw error message
Posted by: natukunda liz
Date: September 17, 2012 08:27AM

i need a trigger to give an error message if invalid data is inserted.here is my trial and its not working. please help on error handling in mysql. thank you.

mysql> DELIMITER //
mysql> CREATE TRIGGER TR_CHECKCONSTRAINT
-> BEFORE INSERT ON TEST_CHECKCO
-> FOR EACH ROW
-> BEGIN
-> DECLARE msg varchar(255);
-> IF NOT new.AGE = 50 THEN
-> SET msg = 'INVALID DATA'
-> SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
-> END IF;
-> END
-> //

Options: ReplyQuote


Subject
Views
Written By
Posted
trigger Throw error message
29060
September 17, 2012 08:27AM
5661
September 18, 2012 12:41AM


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.