MySQL Forums
Forum List  »  Triggers

FORBIDE DELETE
Posted by: Inna M.
Date: April 26, 2006 05:44AM

I looked in the forum about this subject, and there is unfortunetely no concrete answer :(

I have 2 tables: Attributes and IntegerValues. Both of them have an attribute "Value_Id".

Problem: i need to forbide deleting row from tha table IntegerValues if the Value_Id is used in the table Attributes. If it's used in the table Attributes - Trigger has to forbide delete and give back an error message(or something...(?)).

My Trigger is:

CREATE TRIGGER bd BEFORE DELETE on IntegerValues
BEGIN
BEGIN TRANSACTION;

DECLARE val_id int;
select Value_Id into val_id
from Attributes
where Value_Id = old.Value_Id;
if ( attr_Val <> 0 ) then
ROLLBACK;
end if;

END TRANSACTION;
END;

Options: ReplyQuote


Subject
Views
Written By
Posted
FORBIDE DELETE
3078
April 26, 2006 05:44AM
1770
April 26, 2006 08:01AM
1885
April 27, 2006 01:29AM
1797
April 27, 2006 05:53AM
1825
April 27, 2006 11:54AM


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.