1
votes

I have a table employees and a table where I need to store the ones who are not employees anymore. I need to insert the employees deleted to that table with a trigger.

I tried this code but doesn't work

CREATE TRIGGER EX4
   ON  EMPLOYEES
   AFTER delete
AS 
BEGIN
insert into BAIXES
values(@ID, 'deleted')
END

This is what the exercise says (it's translated so it may have translation problems.

Create a trigger that sign up to the previous table, the worker that is removed from the table works. The data of the worker must be saved, and the variables USER and SYSDATE. The trigger must be triggered AFTER DELETE.

2
What is @ID supposed to be? - Gordon Linoff

2 Answers

0
votes

In Oracle, I would expect something like this:

CREATE TRIGGER EX4
   ON  EMPLOYEES
   AFTER delete
AS 
BEGIN
    insert into BAIXES ( . . . )        -- list columns to insert here
        values (:old.?, :old.?, . . . );  -- list columns here with :old prefix
END;
0
votes

You can do it using this command:

INSERT INTO BAIXES(ID, Field1, Field2, [others fields here])
SELECT ID, Field1, Field2, [others fields here] FROM DELETED