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 2005 Forums
 Other SQL Server Topics (2005)
 Triggers using SQL Server Functions

Author  Topic 

kartiknagaraja
Starting Member

2 Posts

Posted - 2007-04-12 : 12:43:13

Hi,
I am still learning the bells and whistles of SQL Server and was wondering if I can find out the query that caused my trigger to fire, so that I can log this in another audit table.
I have an If Update ( My_Column ) trigger set up, where once an update happens to My_Column much information from the updated row along with , Host_Name and App_Name is sent. I also want to send the exact query used to update it, any ideas?
Any comments, suggestions will be greatly appreciated.
Thanks,
Kartik

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-12 : 12:56:47
Just a thought...

lets say you are inserting the data into some table.
INSERT INTO SomeTable (col...)
SELECT ...

you might be able to create a string as
set @str = 'INSERT INTO SomeTable (col...) SELECT ...'
inser into AuditTable ( ...,Query... ) VALUES (..., @str,...)






************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

kartiknagaraja
Starting Member

2 Posts

Posted - 2007-04-12 : 13:00:22
well it is more like.. this column is being updated by many different queries, some in SSIS packages and some via a web app.
What I want to audit with this trigger is that, when the columns value is updated, I want the whole query that was reponsible.
I have narrowed it down to when (by adding getdate() ) and who (by using Host_Name()) but having trouble finding a sql server function that will give me the query that was just run for the update.
Go to Top of Page
   

- Advertisement -