我看了這個article,但它似乎不適用於刪除。試圖創建觸發器,當我得到這個錯誤:如何編寫觸發器以中止MYSQL中的刪除?
Executing SQL script in server
ERROR: Error 1363: There is no NEW row in on DELETE trigger
CREATE TRIGGER DeviceCatalog_PreventDeletion
BEFORE DELETE on DeviceCatalog
FOR EACH ROW
BEGIN
DECLARE dummy INT;
IF old.id = 1 or old.id =2 THEN
SELECT * FROM DeviceCatalog WHERE DeviceCatalog.id=NEW.id;
END IF;
END;
SQL script execution finished: statements: 4 succeeded, 1 failed
NEW.fieldname存在;當你刪除沒有新的數據庫時!該錯誤是明顯的:你不能使用NEW.id因爲新的未在DELETE觸發 – Marco
允許根據連鎖報道的選擇statatement應該失敗 - 你的SELECT語句讀起來就像一個真實的,而不是像'選擇到假'從意欲失敗的文章中。 – miherrma