Solved

Audit Table update via trigger

Posted on 2012-03-30
2
261 Views
Last Modified: 2012-06-21
I'm trying to create an update trigger on a particular table that will fire BEFORE the update takes place. I'd like the trigger to select the values of the record that are about to be updated and insert them into another table first and THEN fire the update statement.

So, prior to updating table1-recordx, I want to insert the values of recordx into table2.

We will be using this technique as a way of auditing changes to a particular table with the ability to easily roll those changes back via a web-app front end screen.

Anyone know of a simple way to do this in SQL Server? Version is 2008 R2 if that matters.
0
Comment
Question by:dsurrett2
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 37788910
You will have to use an INSTEAD OF trigger instead of an AFTER trigger.

SQL Server does not have BEFORE triggers.
0
 

Author Comment

by:dsurrett2
ID: 37813954
Ok, thanks. This looks like the right solution for us. Exactly what I was looking for.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help Required 2 46
get column names from table in vb.net 8 68
Why I am having this error in my query? 2 32
Applying Roles in Common Scenarios 3 13
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question