SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to get the actual query text being fired for a particular operation. I'm trying to implement a...


How to get the actual query text being fired for a particular operation. I'm trying to implement a trigger on a table where i need to store the query also.

Author
Message
sinureddi
sinureddi
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 81
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
GSquared
GSquared
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30015 Visits: 9730
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
Matt Whitfield
Matt Whitfield
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1187 Visits: 719
DBCC InputBuffer (SPID) will give you the text sent to the SQL Server, if that helps.

Atlantis Interactive - SQL Server Tools
My blog
Why I wrote a sql query analyzer clone
Jeffrey Williams 3188
Jeffrey Williams 3188
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9874 Visits: 9994
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
Problems are opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

sinureddi
sinureddi
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 81
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
Matt Whitfield
Matt Whitfield
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1187 Visits: 719
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! BigGrin

Atlantis Interactive - SQL Server Tools
My blog
Why I wrote a sql query analyzer clone
GSquared
GSquared
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30015 Visits: 9730
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search