January 5, 2009 at 4:39 am
Hi All,
Can some one help me in getting the actual query text being used to perform an operation.
I'm doing a Outer Apply with sys.dm_exec_sql_text(deqs.sql_handle),
though this is giving correct info but not in the desired manner.
I'm doing this implementation inside a trigger.
In case of a stored proc call which has some internal DML operations in it, i want the query text as "Exec Procname 'xxxx', 'xxxxx'" which is the actual one which is fired. But the DMV which i've specfied above is giving me the entire content of the SP being fired.
Request help to address my issue.
Thanks in advance.
Srinivas
January 5, 2009 at 3:01 pm
Is there a reason to do this in a trigger, as opposed to working from a trace? A trace will give you exactly what you're looking for, the proc name and parameter values. What are you doing with the data in the trigger?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 5, 2009 at 3:18 pm
DBCC InputBuffer (SPID) will give you the text sent to the SQL Server, if that helps.
Atlantis Interactive - SQL Server Tools
My blog[/url]
Why I wrote a sql query analyzer clone
January 5, 2009 at 5:07 pm
You can get the object using the objectid column - but, if you want the actual stored procedure call you need to get it from a trace.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
January 6, 2009 at 3:25 am
Thank you for the reply.
But, can DBCC Inputbuffer(SPID) in an inline query?
I'm actually trying to monitor the various DML opertaions being performed on a table.
In the update trigger, i'm capturing all the old values of the columns being updated from the table and along with, host name from which query is fired, sql statement used, updated columns (XML format) etc... into a log table.
My query is as below:
INSERT INTO Tablename_Log
SELECT D.Column1 , D.Column2 , D.Column3 , D.Column4 , D.Column5 ,
@FldsUpdated, B.Text
, GetDate(),Host_Name(),A.Session_Id
FROM DELETED D , (select Session_Id, sql_handle from sys.dm_exec_requests where session_id=@@spid) A
OUTER APPLY sys.dm_exec_sql_text(A.sql_handle) B
Thanks And Regards,
Srinivas
January 6, 2009 at 4:02 am
sinureddi (1/6/2009)
But, can DBCC Inputbuffer(SPID) in an inline query?
No - it just gives you what was sent to the server - I wasn't 100% sure where you were coming from so thought I would mention it just in case! 😀
Atlantis Interactive - SQL Server Tools
My blog[/url]
Why I wrote a sql query analyzer clone
January 6, 2009 at 9:55 am
I don't know a way to get exactly what you're looking for in one solution.
I'd log the update (as you're doing), and run a trace. From time-stamps, SPIDs, etc., you should then be able to join the two together after the fact. Trace will give you exact command run, log will give you the rest of it.
It's not ideal, but it will work.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply