简体   繁体   English

在MySQL中转换MSSQL触发器

[英]Converting mssql trigger in mysql

i just moved from mssql to mysql and what i'm doing now is converting all my triggers in mssql to mysql and i'm finding difficulites. 我刚刚从mssql移到mysql,现在我正在做的就是将mssql中的所有触发器都转换为mysql,我发现了难题。 I'm inserting a record into a table called pp_change and when that is done a table called profile should be updated and lastly insert the record in a photo table 我正在将记录插入到名为pp_change的表中,完成后应更新一个名为profile的表,最后将该记录插入到photo表中

DELIMITER $$

CREATE TRIGGER pic_pic AFTER INSERT ON pp_change
FOR EACH ROW
BEGIN      

BEGIN             
    UPDATE profile           
    SET  profile_pix = pp_change.pic           
    FROM Inserted pp_change          
   WHERE profile.email = pp_change.email          

INSERT INTO photos (email,pic,wardrobe,upload_type,pic_view,up_user_id,country,time_group,fpage)                            

SELECT (email,pic,wardrobe,upload_type,pic_view,user_id,country,time_group,fpage) 
from pp_change             

END$$
DELIMITER ;

When i execute i get this error 当我执行我得到这个错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Inserted pp_change 

MySQL has no concept of inserted . MySQL没有inserted概念。 It uses the new variables to store the new values. 它使用new变量来存储新值。 So, you should be using them, and not the original table: 因此,您应该使用它们,而不是原始表:

DELIMITER $$

CREATE TRIGGER pic_pic AFTER INSERT ON pp_change
FOR EACH ROW
BEGIN      

BEGIN             
    UPDATE profile           
        SET  profile_pix = new.pic           
        WHERE profile.email = new.email ;         

    INSERT INTO photos (email, pic, wardrobe, upload_type, pic_view, up_user_id, country, time_group, fpage)                            
        SELECT new.email, new.pic, new.wardrobe, new.upload_type, new.pic_view, new.user_id, new.country, new.time_group, new.fpage;

END$$
DELIMITER ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM