Using an update trigger to update another table

后端 未结 2 367
眼角桃花
眼角桃花 2021-01-28 08:00

The program I am working on has a poorly designed backend and basically there are two different tables needed to hold the exact same information. I am trying to write a trigger

相关标签:
2条回答
  • 2021-01-28 08:39

    You need to close every statement inside the trigger with a ;, and I do mean every.

    CREATE TRIGGER `after_update_A` AFTER UPDATE ON `A` FOR EACH ROW
    BEGIN
        UPDATE TABLE B
        SET  username = NEW.username
           , password = NEW.password
           , email = NEW.email
        WHERE id = NEW.id;    //<<-----------
    END $$
    
    0 讨论(0)
  • 2021-01-28 09:02

    I have the feeling that you are compiling .sql as .sh

    the trigger is .sql and should be executed using

    mysql-batch-commands.html

    p.s. What @Johan says is obviously correct as well

    p.s.2 Now I see another error: you will need a delimiter between the drop and create statements

    0 讨论(0)
提交回复
热议问题