2014-10-20 49 views
0

我寫了一個觸發器INSERT AFTER:,其中I在SELECTJOIN之內。帶有SELECT/JOIN的觸發器插入

DROP TRIGGER IF EXISTS `InsertArticle`; 
DELIMITER // 
CREATE TRIGGER `InsertArticle` AFTER INSERT ON `article` 

FOR EACH ROW 
    insert into log (LogTime, LogIdNote, LogName, LogType, LogIdUser, logTypeCategory, LogTypeUser, LogUrl) 
    select NEW.ArticleTime, NEW.idArticle, NEW.ArticleName, 1, NEW.ArticleToUserID, NEW.ArticleCategory, u.UsersTypeAccount, ct.URLCategorysubscribetotype 
    from users u where u.idUsers = NEW.ArticleToUserID LEFT JOIN categorysubscribetotype ct ON ct.CategoryTypeCategorysubscribetotype = 1; 
END 
// 
DELIMITER ; 

當我試圖創建觸發器,我得到錯誤1422。 可能是我有一個錯誤的觸發sintax?

回答

1

試試這個:

DROP TRIGGER IF EXISTS `InsertArticle`; 
DELIMITER // 
CREATE TRIGGER `InsertArticle` AFTER INSERT ON `article` 

FOR EACH ROW 
    insert into log (LogTime, LogIdNote, LogName, LogType, LogIdUser, logTypeCategory, LogTypeUser, LogUrl) 
    select NEW.ArticleTime, NEW.idArticle, NEW.ArticleName, 1 as LogType, NEW.ArticleToUserID, NEW.ArticleCategory, u.UsersTypeAccount, ct.URLCategorysubscribetotype 
    from users u LEFT JOIN categorysubscribetotype ct ON ct.CategoryTypeCategorysubscribetotype = 1 where u.idUsers = NEW.ArticleToUserID; 
END 
// 
DELIMITER ; 
+0

有錯誤太 – Elhan 2014-10-20 08:39:38

+0

顯式或隱式提交在存儲函數或觸發器是不允許的。 #1422 – Elhan 2014-10-20 09:38:23

+0

可能是Mysql不支持? – Elhan 2014-10-20 18:06:50