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 tab
Since you didn't post the error, I have to guess. My guess is that the problem is that name
is not a valid identifier in this context. You need to reference either :new.name
or :old.name
. :old.name
will be NULL
on an insert while :new.name
will be NULL
on a delete so I'm assuming you want something like
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 (:new.name, 'Insert into persons');
ELSE
INSERT INTO logs (who, what) VALUES (:old.name, 'Delete from persons');
END IF;
END;