MySQL Forums
Forum List  »  Triggers

Re: Trigger question
Posted by: Peter Brawley
Date: October 06, 2014 11:17AM

MySQL Triggers are awkward for such validation. It's usually best to validate in the application layer, in the module that runs the input form, so the user can correct such errors before the record is submitted.

If for some reason it absolutely must be done in a Trigger, and if the column is defined NOT NULL, here is one way ...

create trigger tupd before update on t for each row
begin
declare msg varchar(255);
if new.string='some bad value' then
set new.string=null; -- mysql will reject null
set msg = 'info for user';
signal sqlstate '45000' set message_text = msg; -- inform user
end if;
end;

Options: ReplyQuote


Subject
Views
Written By
Posted
2183
October 06, 2014 09:42AM
Re: Trigger question
956
October 06, 2014 11:17AM


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.