Expert Software Company : News

miercuri, 26 mai 2010

Trigger Mysql Before DELETE

CREATE TRIGGER `articole_before_del_tr` BEFORE DELETE ON `articole`
FOR EACH ROW
BEGIN
IF EXISTS (SELECT CodArticol FROM miscari WHERE CodArticol = OLD.CodArticol) THEN
SELECT 0 FROM `Articolul are miscari. NU se poate sterge` INTO @error;
END IF;
END;


SAU

BEGIN
IF (SELECT COUNT(*) FROM miscari WHERE CodArticol=old.CodArticol)!=0
THEN
INSERT error_msg VALUES ('Foreign Key Constraint Violated!');
END IF;
END

Niciun comentariu:

Trimiteți un comentariu