Solved

Audit Table update via trigger

Posted on 2012-03-30
2
259 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server stored proc 2 19
Extract string portion 2 24
T-SQL - How to use like '%%' operator to search an integer 2 26
Find results from sql within a time span 11 30
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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