0

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 に投稿されている多くの方法を試しましたが、それでもうまくいきません。

4

3 に答える 3

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;
于 2013-03-05T08:22:45.473 に答える
0

2 つのソリューションを試してください。1.すべてのコードを 1 つのトリガー内に配置し、複数の begin および end ステートメントを使用します 2.区切り文字、Begin および End を削除します

于 2013-03-05T08:16:07.583 に答える
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 ;
于 2013-03-05T08:29:50.177 に答える