I have a persons table with a name and id as well as a logs table with attributes who and what.
I want to insert into the logs table when I delete or insert into the persons table.
This is what I have so far:
CREATE OR REPLACE TRIGGER add_del
BEFORE INSERT OR DELETE ON persons
FOR EACH ROW
BEGIN
IF INSERTING THEN
INSERT INTO logs (who, what) VALUES (name, 'Insert into persons');
ELSE
INSERT INTO logs (who, what) VALUES (name, 'Delete from persons');
END IF;
END;
/
Why does this compile with the error:
Warning: Trigger created with compilation errors.
Since you didn’t post the error, I have to guess. My guess is that the problem is that
nameis not a valid identifier in this context. You need to reference either:new.nameor:old.name.:old.namewill beNULLon an insert while:new.namewill beNULLon a delete so I’m assuming you want something like