Solved

Audit Table update via trigger

Posted on 2012-03-30
2
256 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:
ScottPletcher 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now