Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6807267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:48:39+00:00 2026-05-26T19:48:39+00:00

I need to create a trigger that writes changes in a shadow table. I

  • 0

I need to create a trigger that writes changes in a shadow table. I know how to create the trigger but my challenge is that I need the records in the new table to exist even after a rollback.

This is an example of how the output will look like

INSERT INTO department VALUES (95, 'PURCHASING', 'CHICAGO');<br>
ROLLBACK;

1 rows inserted.
rollback complete.

SELECT * FROM department_log;

DEPARTMENT_ID           DEPARTMENT_NAME       ADDRESS               OPERATION_TIME            
---------------------- -------------------- -------------------- ------------------ 
90                      HR                    CHICAGO               03-NOV-11
95                      PURCHASING            CHICAGO               03-NOV-11

SELECT * from department WHERE department_id >= 90;

DEPARTMENT_ID           DEPARTMENT_NAME       ADDRESS              
---------------------- -------------------- -------------------- 
90                      HR                    CHICAGO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:48:40+00:00Added an answer on May 26, 2026 at 7:48 pm

    You’ll need to use autonomous transactions.

    SQL> create table t (col1 number);
    
    Table created.
    
    SQL> create table t_shadow( col1 number, dt date );
    
    Table created.
    
    SQL> create trigger trg_t
      2    before insert on t
      3    for each row
      4  declare
      5    pragma autonomous_transaction;
      6  begin
      7    insert into t_shadow( col1, dt )
      8      values( :new.col1, sysdate );
      9    commit;
     10  end;
     11  /
    
    Trigger created.
    
    SQL> insert into t values( 1 );
    
    1 row created.
    
    SQL> rollback;
    
    Rollback complete.
    
    SQL> select * from t;
    
    no rows selected
    
    SQL> select * from t_shadow;
    
          COL1 DT
    ---------- ---------
             1 09-NOV-11
    

    Note that if you find yourself using autonomous transactions for anything other than persistent logging, you are almost certainly doing something wrong. Autonomous transactions are a very dangerous and very frequently misused feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok. So I know how to create a trigger that makes changes to Table
I need to write a trigger that will create a record in another table.
Below is trigger that I need to create but It is not getting created.Please
I'm working with wordpress and need to create a trigger that updates a table
I need to create trigger in SQL Server 2008 that gone insert all values
Is it possible to create a trigger on a table that is initiated when
I need to do a trigger but the only difference that I'm trying to
I am renewing a record. I need to create a trigger that will automatically
I need to create Trigger for delete action which backsup all fields old value
I need to create a trigger in every database on my sql 2005 instance.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.