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?
9125
April 17, 2005 01:10PM
5163
April 17, 2005 04:00PM
9936
April 27, 2005 04:01AM
4979
April 27, 2005 04:04AM
3949
May 28, 2008 05:28PM
4125
April 27, 2005 04:13AM
3700
April 27, 2005 04:30AM
3677
April 27, 2005 05:09AM
3455
April 27, 2005 06:45AM
4107
December 29, 2005 03:45PM
4223
December 30, 2005 08:04AM
3690
January 04, 2006 12:50PM
4951
January 04, 2006 05:43PM
3304
January 04, 2006 07:38PM
3889
January 05, 2006 10:08AM
3475
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.