update a table, however I would like to save the old news in an another tabl

Hello all; I have a table called table_one,

That contains the following information
carid            place
Benz            New York
BMW            London
This information will usually be updated in the near future, however, I would like a situation where before information is updated, the old information is stored in another table called table_two first. for example, table_one, say that New York is so updated to Toronto, I want

CARiD place
Benz New York

first recorded in table_two before the update is done. How can I do to make it. Thank you

You can use a trigger to insert the old lines to another table.

syntax:

CREATE or REPLACE TRIGGER trigger_name
BEFORE UPDATE
    ON table_name
    [ FOR EACH ROW ]
DECLARE
    -- variable declarations
BEGIN
    -- trigger code
EXCEPTION
    WHEN ...
    -- exception handling
END;

for example

CREATE OR REPLACE TRIGGER emp_before_update
BEFORE UPDATE ON empployee FOR EACH ROW
DECLARE
    v_username varchar2(10);
BEGIN
    insert into employee_backup
     (employee_id,
      first_name,
      last_name)
    values
     (:old.employee_id,
      :old.first_name,
      :old.last_name);
END;

Tags: Database

Similar Questions

Maybe you are looking for