我有一个名为daire的表,它有名为Kiraci,D_ID,Sahip的列。 D_ID是PK列。我想要的是当我改变Kiraci值时,我希望触发器删除一行或将一个新行插入另一个表。我试图创建一个像书面底部的触发器:
CREATE TRIGGER daireBosalt AFTER UPDATE ON daire
FOR EACH ROW
BEGIN
IF NEW.Kiraci IS NULL THEN
DELETE FROM kontrat WHERE kontrat.D_ID = NEW.D_id;
ELSEIF NEW.Kiraci IS NOT NULL THEN
INSERT INTO kontrat (D_ID, BAy, BGun, BYil, Tutar, Sahip, Sure, Depo, Komisyon) VALUES (NEW.D_id, '01', '01','2014','100', NEW.Sahip,'1','100','100')
END IF;
END;
当我尝试创建此脚本时,它会一直给我语法错误。
答案 0 :(得分:1)
创建触发器时更改分隔符:
delimiter $$
CREATE TRIGGER daireBosalt AFTER UPDATE ON daire
FOR EACH ROW
BEGIN
IF NEW.Kiraci IS NULL THEN
DELETE FROM kontrat WHERE kontrat.D_ID = NEW.D_id;
ELSEIF NEW.Kiraci IS NOT NULL THEN
INSERT INTO kontrat (D_ID, BAy, BGun, BYil, Tutar, Sahip, Sure, Depo, Komisyon) VALUES (NEW.D_id, '01', '01','2014','100', NEW.Sahip,'1','100','100')
END IF;
END $$
delimiter ;