Skip to content
Advertisement

Cascade DELETE to row of another table

When i try to delete a “livro” with id = id_capitulo i want to delete the “livro” and the “capitulo”, however when deleting a “livro” it returns success, but it does not delete “livro” or “capitulo” … I tried to put a counter in case there is more than 1 “capitulo” in the table with an id equal to the id I put when I ask to delete it delete

Advertisement

Answer

When i try to delete a “livro” with id = id_capitulo i want to delete the “livro” and the “capitulo”

You don’t need a trigger for this. Instead, you can have a foreign key with the on delete cascade option:


As for your existing code: since you have a delete trigger, you need to use pseudo-table old rather than new (which is actually empty):

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement