Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Triggers for insert,update,delete in SQL server

Author  Topic 

mkfrns
Starting Member

2 Posts

Posted - 2013-12-09 : 12:17:22
I have created audit table

CREATE TABLE Test_Audit
(column_name varchar(50),
old_value varchar(100),
new_value varchar(100),
Table_name varchar(100),
Username varchar(100),
action varchar(100),
Audit_Timestamp datetime
)

and I have table named testing
create table testing
(number int, name varchar(10))

I want trigger for insert,delete,update for table testing and the entries should be added to Test_Audit..I want the old values,new values,column name to be displayed in Audit table..

My trigger only works with 1 column table.If i run for 2 column table,the latest modified column is updated in oldvalue and new value..but actually 2 values should get updated in oldvalue and new value for 2 columns table

could anyone please help me with the queries??Your help is appreciated

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-12-09 : 12:32:36
Here are some links of how to set up audit triggers:
http://www.softcodearticle.com/2012/11/imlementing-generic-audit-trail-trigger-in-sql-server/
http://gallery.technet.microsoft.com/scriptcenter/Create-Audit-Table-and-5cd69d5d

Here is a link to how to setup Auditing in the DB itself:
http://bradmcgehee.com/2010/03/30/an-introduction-to-sql-server-2008-audit/
Go to Top of Page
   

- Advertisement -