2014-04-28 30 views
0
I want to create a trigger wich will be executed when a new row is about to be 
inserted if my condition is satified (latest version = 1) all privious row will 
be updated with latest version = 0 

CREATE TRIGGER remiseazero 
BEFORE INSERT 
ON wp_stattype2_3_activite 
FOR EACH ROW 
BEGIN 
IF NEW.latestversion = 1 
THEN 
update wp_stattype2_3_activite 
set latestversion = 0 where typecas = new.typecas; 
END IF; 
END;$$ 

錯誤:MySQL錯誤任何幫助將apreciated

#1064 - 您的SQL語法錯誤;檢查與您的MySQL服務器版本對應的手冊,以便在第9行的''附近使用正確的語法。

+0

你是如何創建觸發器的?通過phpMyAdmin?如果是這樣,你有沒有向phpMyAdmin表明$$應該是你的分隔符? –

回答

0

放置分隔符。並在END之後刪除;

DELIMITER $$ 
CREATE TRIGGER remiseazero 
BEFORE INSERT 
ON wp_stattype2_3_activite 
FOR EACH ROW 
BEGIN 
IF (NEW.latestversion = 1) THEN 
    update wp_stattype2_3_activite set latestversion = 0 where typecas = NEW.typecas; 
END IF; 
END$$ 
DELIMITER ; 
+0

@ user3581207解決問題? –