Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Audit Table update via trigger

Posted on 2012-03-30
2
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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 …
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

609 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