MySQL Trigger: Delete From Table AFTER DELETE

后端 未结 3 1538
失恋的感觉
失恋的感觉 2020-12-01 18:17

Scope: Two tables. When a new patron is created, they have some information about them stored into a 2nd table (This was done using a trigger as well, it works as expected)

3条回答
  •  情话喂你
    2020-12-01 18:29

    I think there is an error in the trigger code. As you want to delete all rows with the deleted patron ID, you have to use old.id (Otherwise it would delete other IDs)

    Try this as the new trigger:

    CREATE TRIGGER log_patron_delete AFTER DELETE on patrons
    FOR EACH ROW
    BEGIN
    DELETE FROM patron_info
        WHERE patron_info.pid = old.id;
    END
    

    Dont forget the ";" on the delete query. Also if you are entering the TRIGGER code in the console window, make use of the delimiters also.

提交回复
热议问题