我有兩張表,我想在插入,更新或刪除時同步 我可以在同一張桌子上創建多個觸發器嗎?我想在同一張桌子上創建更多的觸發器
我已經寫了類似的代碼..但它不起作用..但是當我只創建一個觸發器,它工作正常。
的代碼是類似的東西:
CREATE TRIGGER photosinsert BEFORE INSERT上的照片 FOR EACH ROW BEGIN INSERT INTO old_photo SET PHOTOID = NEW.photo_id,photo_original = NEW.file_name ; END;
分界符|
CREATE TRIGGER photosupdate BEFORE UPDATE ON照片 FOR EACH ROW BEGIN UPDATE SET old_photo = photo_original NEW.file_name WHERE PHOTOID = NEW.photo_id ; END;
分界符|
CREATE TRIGGER photosdelete BEFORE刪除照片 FOR EACH ROW BEGIN DELETE FROM old_photo WHERE PHOTOID = OLD.photo_id ; END;
請問有沒有解決方案?
感謝Nakti,我試圖做到這一點,但它失敗了。 但我找到了解決辦法..我所做的是刪除分隔符,並開始,END 代碼將是這樣的: CREATE TRIGGER photosinsert BEFORE INSERT上的照片FOR EACH ROW INSERT INTO old_photo SET PHOTOID = NEW.photo_id, photo_original = NEW.file_name; CREATE TRIGGER photosupdate在更新照片之前對每行更新old_photo SET photo_original = NEW.file_name WHERE PhotoID = NEW.photo_id; 創建觸發器photosdelete之前刪除照片每行刪除從old_photo其中PhotoID = OLD.photo_id; – 2010-06-24 12:13:06