July 2, 2004 at 1:17 am
Hi there,
anybody knows if it's possisble to catch the latest sql statement fired on a certain server ?
I have this trigger that logs all deletes on a crucial tablem but i would be nice to catch the delete statement as well...
any (other) ideas ?
tnx a lot !
July 2, 2004 at 4:10 am
July 2, 2004 at 4:43 am
Figured it out meantime, thanks for the help!
June 7, 2006 at 9:39 am
What if the statement you're trying to catch is within a stored proc and you want to catch it within the same stored proc and log it to a "tracking table"?
June 8, 2006 at 6:31 am
Are you trying to capture a record of dynamic SQL? If so, it ought to be fairly easy. Rewrite your SP to build the SQL string in a variable, instead of directly in the argument of the EXEC function. Then, write the value of the variable to your tracking table, either before or after you run the EXEC, depending on what you want to capture.
If you just want to know when an SP runs, you can just add an extra INSERT statement to the SP to add the log entry to your tracking table. Note that this can negatively impact performance, especially if you want to capture a great deal of information (e.g. spid, user, variable values).
June 8, 2006 at 10:52 am
Also, check out fn_get_sql in the BOL. It is better than DBCC INPUTBUFFER.
You might also want to consider using a trigger (ON DELETE) to help capture what you want. Maybe set up the trigger to run fn_get_sql when someone does a delete.
-SQLBill
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply