MySQL Trigger: Delete from "patron_info" After Deleting from "patrons"
To establish a trigger that automatically deletes rows from the "patron_info" table when corresponding rows are removed from the "patrons" table:
Syntax Error Correction:
The original trigger syntax error stems from attempting to use both "patrons.id" and "old.id" in the "WHERE" clause. To correctly delete rows from "patron_info" based on the deleted "patron" ID, the trigger should use "old.id":
CREATE TRIGGER log_patron_delete AFTER DELETE on patrons
FOR EACH ROW
BEGIN
DELETE FROM patron_info
WHERE patron_info.pid = old.id;
END
Additional Considerations:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3