function for current transaction....

  • Hi,

    is there a function to return the current update/select statement that a session is attempting to run during a deadlock.

    If say I have sid 55, is there a function I can provide the id into to return the command.

    Any help welcome.

    Eamon

  • Eamon

    You can use the sys.dm_exec_sessions view to find out what session(s) a given SID has open.  Then simply put the session number(s) into DBCC INPUTBUFFER command.

    John

  • John, heyyyy...thanks a million, perfect

  • Or you can use sys.dm_exec_requests and pass the SQL handle to the sys.dm_exec_sql_text function and get the entire sql statement. (DBCC Inputbuffer only displays the first 255 characters)

    select * from sys.dm_exec_requests req cross apply sys.dm_exec_sql_text(req.sql_handle) txt

    where req.session_id = @spid

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gail....that's even better...thanks !!!

  • Pleasure

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply