I have this database schema for an electronic calendar.
I have a table of events and one of equipment which is a many to many relationship. Once an event is deleted, I need to change the status of the equipment (eg, projector, notebook, pointer) related to that event, which are stored in the evt_equip
table.
My idea is to do this with a Trigger, so that once an event is eliminated, the trigger is triggered and the status of the equipment related to the event is changed (from 1 to 0).
I think the right way is to do an UPDATE with JOIN but there's the problem. I passed it trying and I do not get the result.
The code I was testing is this:
delimiter //
create trigger evento_AD after delete on evento for each row
begin
declare id int;
set id=old.idevento;
insert into pruebas(valor) value(id);
update equipamiento e inner join evt_equip ee on e.idequipamiento = ee.idequip set estado=0 where ee.idevento=id;
end//