Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

How to get the command text in a trigger that cause the update?

$
0
0

Hi All

I create a update trigger for a table, if the specific column is updated, my trigger will save the old value, new value and the sql statement to another table, now old value and new value is in "inserted" and "deleted" virtual table, how to get the sql statement that cause the update?

I use this code to retrieve the sql statement:

select command,text FROM sys.dm_exec_requests er cross apply sys.dm_exec_sql_text(er.sql_handle) AS st WHEREer.session_id=@@SPID

The return result is not the SQL statement that cause the update but the "Create trigger" statement - I test the trigger just after create trigger.

What am I missing?


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>