MySQL Forums
Forum List  »  Triggers

Syntax Trigger in Mysql
Posted by: jororemy jor
Date: October 13, 2015 08:51AM

Hello,
Doe trigger is it possible in MySQL? if so can you help me and tell me what's wrong in my syntax.
Thank you

DROP TRIGGER IF EXISTS et_update_dru//
CREATE TRIGGER mdm_et_update_dru
AFTER UPDATE ON mdm_et_emp_pa
FOR EACH ROW
BEGIN
DECLARE uiduser,uidrole INT;
SELECT u.uid INTO uiduser
FROM user u
WHERE u.ref_id = NEW.ref_per and u.ref_a = NEW.ref_a;

IF uiduser IS NOT NULL THEN
UPDATE user
SET ref_id = NEW.ref_per, ref_a = NEW.ref_a, mail = NEW.mail, na = NEW.lo, pass = MD5(NEW.pa), sts = 1
WHERE ref_id = NEW.ref_per and ref_a = NEW.ref_a;
ELSE
INSERT INTO user (ref_id, ref_a, mail, na, pass, sts)
VALUES (NEW.ref_per, NEW.ref_a, NEW.mail, NEW.lo, MD5(NEW.pa), 1);

END IF;

IF NEW.fon != OLD.fon THEN
UPDATE user_ro ur, ro r, user u set ur.id = r.id WHERE u.ref_id = NEW.ref_per and u.id = ur.id and NEW.fon = r.na;
END IF;
IF NEW.act !=OLD.act then
SELECT ur.id INTO uidrole
FROM user_ro ur, user u, ro r
WHERE ur.id=u.id and u.ref_id=NEW.ref_per and r.na=OLD.act and r.id=ur.id;
IF uidrole IS NOT NULL THEN
IF ep.act=QUOTE("Im d'ise") or ep.act='Fo de ce' THEN
UPDATE user_ro ur, user u set ur.id = 19 WHERE u.ref_id = NEW.ref_pers and u.id = ur.id;
ELSE
UPDATE user_ro ur, ro r, user u set ur.id = r.id WHERE u.ref_id = NEW.ref_per and u.id = ur.id and NEW.act = r.na;
END IF;
ELSE
IF ep.act=QUOTE("Im d'ise") or ep.act='Fo de ce' THEN
INSERT INTO user_ro (id,id)
SELECT u.id, 19
FROM user u
WHERE u.ref_id = NEW.ref_per;
ELSE
INSERT INTO user_ro (id,id)
SELECT u.id, r.id
FROM ro r, user u
WHERE NEW.act=r.na and NEW.ref_per=u.ref_id;
END IF;
END IF;
END IF;
END

delimiter //

Options: ReplyQuote


Subject
Views
Written By
Posted
Syntax Trigger in Mysql
1764
October 13, 2015 08:51AM
894
October 13, 2015 12:26PM
1223
October 14, 2015 01:10AM
918
October 14, 2015 08:53AM


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.