I'm making MySql database, where I have film table:
- id
- title
- amount
- available
- description
and copy table with foreign key film_id:
- id
- film_id
And now I've written after delete trigger on copy:
UPDATE `film`
SET available = available - 1
WHERE OLD.film_id = id;
And now I would like to write before delete trigger on film, due to fact that film is contrained by copy so I write:
DELETE FROM copy WHERE copy.film_id = OLD.id;
Here error occurs:
Can't update table 'film' in stored function/trigger because it already used by statement which invoked this stored function/trigger.
I would like to delete film -> delete copy -> update film (ERROR)