I have the trigger:
create or replace
TRIGGER JACKET_DELETE
BEFORE DELETE ON JACKET
FOR EACH ROW
BEGIN
DELETE FROM PORT
WHERE EXISTS
(SELECT * FROM port LEFT JOIN device on port.fkdevice = device.pkid
where port.fkjacket = :old.pkid
and device.fkdevice_type = 1);
UPDATE PORT
set port.fkjacket = null, port.fkport = null
WHERE EXISTS
(SELECT port.fkjacket, port.fkport FROM port LEFT JOIN device on port.fkdevice = device.pkid
where port.fkjacket = :old.pkid
and device.fkdevice_type <> 1);
END;
For some reason, when the where
in the delete
matches, it deletes the WHOLE port
table! I thought my SQL was correct, but obviously it's not, and I can't see what's wrong with it. Can anyone see the issue that is making it do this?
When the update
matches, everything works as expected.
table structure: port links to device, jacket, and port