sql >> Databasteknik >  >> RDS >> Mysql

Trigger Insert med en SELECT/JOIN

Prova detta:

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 ;



  1. wildfly registrerar mysql som en datakälla

  2. Automatisk ökning i tillfällig tabell

  3. Hierarkisk SQL-fråga

  4. Hur använder jag CREATE OR REPLACE?