我想为1张桌子制作2-3个触发器。例如(这些是我的查询):
DELIMITER $$
CREATE OR REPLACE TRIGGER IF EXISTS insert_before_update_slugrapat BEFORE UPDATE ON slugrapat
FOR EACH ROW
BEGIN
INSERT INTO record_pemakaian_slug_rapat(rc_sr_size, rc_sr_stockawal, rc_sr_holling, rc_sr_store, rc_sr_sales, rc_sr_sisa, rc_sr_lastdate)
VALUES(new.sr_size, new.sr_stockawal, new.sr_holling, new.sr_store, new.sr_sales, new.sr_sisa, new.sr_lastdate);
/
CREATE OR REPLACE TRIGGER IF EXISTS insert_before_update_slugrapat BEFORE UPDATE ON slugrapat
FOR EACH ROW
BEGIN
INSERT INTO so_slugrapat(sr_size, sr_sisa, sr_stockakhir, sr_stockopname, sr_lastdate)
VALUES(new.sr_size, new.sr_sisa, new.sr_stockakhir, new.sr_stockopname, new.sr_lastdate);
END $$
DELIMITER ;
错误说:
Error code 1064, SQL state 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TRIGGER IF EXISTS insert_before_update_slugrapat BEFORE UPDATE ON slugrapat
FOR ' at line 1
我尝试了很多已经在stackoverflow上发布的方法,但它仍然不起作用。
答案 0 :(得分:0)
尝试两种解决方案。 1.将所有代码放在一个触发器中,并使用多个开始和结束语句 2.删除分隔符,开始和结束
答案 1 :(得分:0)
请检查:
DROP TRIGGER insert_before_update_slugrapat;
DELIMITER $$
CREATE TRIGGER insert_before_update_slugrapat
BEFORE UPDATE
ON slugrapat
FOR EACH ROW
BEGIN
INSERT INTO record_pemakaian_slug_rapat(rc_sr_size,
rc_sr_stockawal,
rc_sr_holling,
rc_sr_store,
rc_sr_sales,
rc_sr_sisa,
rc_sr_lastdate)
VALUES (new.sr_size,
new.sr_stockawal,
new.sr_holling,
new.sr_store,
new.sr_sales,
new.sr_sisa,
new.sr_lastdate);
INSERT INTO so_slugrapat(sr_size,
sr_sisa,
sr_stockakhir,
sr_stockopname,
sr_lastdate)
VALUES (new.sr_size,
new.sr_sisa,
new.sr_stockakhir,
new.sr_stockopname,
new.sr_lastdate);
END$$
DELIMITER;
答案 2 :(得分:0)
DELIMITER $$
DROP TRIGGER IF EXISTS insert_before_update_slugrapat;
CREATE TRIGGER insert_before_update_slugrapat BEFORE UPDATE ON slugrapat
FOR EACH ROW
BEGIN
INSERT INTO record_pemakaian_slug_rapat(rc_sr_size, rc_sr_stockawal, rc_sr_holling, rc_sr_store, rc_sr_sales, rc_sr_sisa, rc_sr_lastdate)
VALUES(new.sr_size, new.sr_stockawal, new.sr_holling, new.sr_store, new.sr_sales, new.sr_sisa, new.sr_lastdate);
END $$
DROP TRIGGER IF EXISTS insert_before_update_slugrapat_1;
CREATE TRIGGER insert_before_update_slugrapat_1 BEFORE UPDATE ON slugrapat
FOR EACH ROW
BEGIN
INSERT INTO so_slugrapat(sr_size, sr_sisa, sr_stockakhir, sr_stockopname, sr_lastdate)
VALUES(new.sr_size, new.sr_sisa, new.sr_stockakhir, new.sr_stockopname, new.sr_lastdate);
END $$
DELIMITER ;