Question

In SQL Server 2008, let's say I have a table with a view and INSTEAD OF triggers on it.

When I insert or update, is there a way inside the trigger to determine the SQL query that was used to invoke the trigger?

For example, if I do the following:

UPDATE MyView SET Address = '123 Main St'

Is there a way inside the trigger to get the actual SQL query that was used, i.e.,

UPDATE MyView SET Address = '123 Main St'

I hope this makes sense.

Thanks.

Was it helpful?

Solution

No, the trigger isn't invoked by that statement - the triggers is fired from the RDBMS because the condition it's defined for (INSERT, UPDATE or DELETE) has occurred.

The trigger is totally asynchronous from the actual statement, and no, you cannot get the T-SQL query that caused the trigger to fire. All you can rely on are the Inserted and Deleted pseudo tables that are available inside the trigger which tell you what rows were inserted, deleted, updated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top