Enforce business rule with before insert trigger?
Posted by:
MySQL User
Date: April 17, 2005 01:10PM
Hi,
I'm experimenting with MySQL 5's trigger support, and have happened across a nut I'm unable to crack. Suppose I want to enforce some biz rule in a trigger any time an INSERT query is executed on the table "product". My desired action for the query not following this rule is failed execution.
So for example suppose I want the trigger to make sure any inserted product price is greater than $10. Therefore the trigger would check whether this is the case, and if not, produce some sort of error messages and deny the target query from occurring. That trigger might look like this:
create trigger bi_product before insert on product
FOR EACH ROW
BEGIN
SET @price = "";
IF NEW.price < 10 THEN
/* DO SOMETHING TO CAUSE OPERATION TO FAIL */
END IF;
END//
Can anybody tell me what I'm supposed to enter in the /* */ line in order to make this happen? Perhaps speaking in more general terms, how can I use MySQL's trigger feature to enforce business rules in this manner, also making sure I'm passing some sort of coherent message back to the user regarding the problem?
Thank you!
G
Subject
Views
Written By
Posted
Enforce business rule with before insert trigger?
8344
April 17, 2005 01:10PM
4310
April 17, 2005 04:00PM
9519
April 27, 2005 04:01AM
4135
April 27, 2005 04:04AM
3418
May 28, 2008 05:28PM
3923
April 27, 2005 04:13AM
3494
April 27, 2005 04:30AM
3518
April 27, 2005 05:09AM
3302
April 27, 2005 06:45AM
3310
December 29, 2005 03:45PM
3261
December 30, 2005 08:04AM
3412
January 04, 2006 12:50PM
4605
January 04, 2006 05:43PM
3108
January 04, 2006 07:38PM
3134
January 05, 2006 10:08AM
3288
January 06, 2006 12:52PM
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.