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?
8302
April 17, 2005 01:10PM
4286
April 17, 2005 04:00PM
9480
April 27, 2005 04:01AM
4120
April 27, 2005 04:04AM
3397
May 28, 2008 05:28PM
3908
April 27, 2005 04:13AM
3468
April 27, 2005 04:30AM
3499
April 27, 2005 05:09AM
3282
April 27, 2005 06:45AM
3288
December 29, 2005 03:45PM
3241
December 30, 2005 08:04AM
3389
January 04, 2006 12:50PM
4578
January 04, 2006 05:43PM
3091
January 04, 2006 07:38PM
3114
January 05, 2006 10:08AM
3268
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.