Home » RDBMS Server » Server Administration » Shadow tables
Shadow tables [message #55621] Tue, 04 February 2003 16:08 Go to next message
Kalyan
Messages: 16
Registered: October 2001
Junior Member
hi,
Is there a feature in oracle that enables us to automatically maitain the history of changes made to a record in a table.

e.g. for a table PERSON there is a PERSON_SHADOW (this table could be named anything but represents a shadow of the main table), before making a change to the record in PERSON, the row should get moved to PERSON_SHADOW and then the record in PERSON should be updated.

If yes, can you give me references how to go about doing this?

-dasika
Re: Shadow tables [message #55623 is a reply to message #55621] Tue, 04 February 2003 17:58 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
use triggers.
this trigger moves data when ANY COLUMN in dept is updated.
You can SPECIFY A PARTICULAR COLUMN optionally.
~
"afiedt.buf" 8 lines, 145 characters

  1  create or replace trigger
  2  tri1
  3  before update on dept
  4  for each row
  5  begin
  6  insert into dept_back values (:old.deptno,:old.dname,:old.loc);
  7* end;
SQL> /

Trigger created.

SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> select * from dept_back;

no rows selected

SQL> update dept set dname='new' where deptno=10;

1 row updated.

SQL> update dept set loc='boston';

4 rows updated.

SQL> select * from dept_back;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        10 new            NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 new            boston
        20 RESEARCH       boston
        30 SALES          boston
        40 OPERATIONS     boston

Previous Topic: Re: archive log list doesn't work as sysdba
Next Topic: ORA -03121
Goto Forum:
  


Current Time: Thu Sep 19 22:56:48 CDT 2024