Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. SELECT
  2.  
  3. -- SESSION_ID
  4. ------ ID of the session to which this request is related
  5. R.SESSION_ID,
  6.  
  7. -- BLOCKING_SESSION_ID
  8. ------ ID of the session that is blocking the request. If this column is NULL, the request is not blocked, or the session information of the blocking session is not available (or cannot be identified).
  9. ------ -2 = The blocking resource is owned by an orphaned distributed transaction.
  10. ------ -3 = The blocking resource is owned by a deferred recovery transaction.
  11. ------ -4 = Session ID of the blocking latch owner could not be determined at this time because of internal latch state transitions.
  12. R.BLOCKING_SESSION_ID,
  13.  
  14. -- REQUEST_START_TIME
  15. ------ Timestamp when the request arrived.
  16. R.start_time AS REQUEST_START_TIME,
  17.  
  18. R.STATUS,
  19. S.HOST_NAME,
  20. CASE
  21. WHEN S.LOGIN_NAME = S.ORIGINAL_LOGIN_NAME THEN S.LOGIN_NAME
  22. ELSE S.LOGIN_NAME + ' (' + S.ORIGINAL_LOGIN_NAME + ')'
  23. END AS LOGIN_NAME,
  24. S.PROGRAM_NAME,
  25. DB_NAME(R.DATABASE_ID) AS DATABASE_NAME,
  26. R.COMMAND,
  27.  
  28. -- CURRENT_WAIT_TYPE
  29. ------ If the request is currently blocked, this column returns the type of wait.
  30. R.WAIT_TYPE AS CURRENT_WAIT_TYPE,
  31.  
  32. -- WAIT_TIME
  33. ------ If the request is currently blocked, this column returns the duration in milliseconds, of the current wait.
  34. R.wait_time AS WAIT_TIME,
  35.  
  36. -- ROW_COUNT
  37. ------ Number of rows that have been returned to the client by this request.
  38. R.ROW_COUNT,
  39.  
  40. -- OPEN_TRANSACTION_COUNT
  41. ------ Number of transactions that are open for this request.
  42. R.OPEN_TRANSACTION_COUNT,
  43.  
  44. -- SESSION_REQUEST_ID
  45. ------ ID of the request. Unique in the context of the session.
  46. R.REQUEST_ID AS SESSION_REQUEST_ID,
  47.  
  48. -- LAST_WAIT_TYPE
  49. ------ If this request has previously been blocked, this column returns the type of the last wait.
  50. R.LAST_WAIT_TYPE,
  51.  
  52. -- LOCK_TIMEOUT
  53. ------ Lock time-out period in milliseconds for this request.
  54. R.lock_timeout AS LOCK_TIMEOUT,
  55.  
  56. -- DEADLOCK_PRIORITY
  57. ------ DEADLOCK_PRIORITY setting for the request.
  58. R.deadlock_priority AS DEADLOCK_PRIORITY,
  59.  
  60. -- TRANSACTION_ISOLATION_LEVEL
  61. ------ Isolation level with which the transaction for this request is created.
  62. CASE R.TRANSACTION_ISOLATION_LEVEL
  63. WHEN 0 THEN 'UNSPECIFIED'
  64. WHEN 1 THEN 'READUNCOMITTED'
  65. WHEN 2 THEN 'READCOMMITTED'
  66. WHEN 3 THEN 'REPEATABLE'
  67. WHEN 4 THEN 'SERIALIZABLE'
  68. WHEN 5 THEN 'SNAPSHOT'
  69. ELSE CAST(R.TRANSACTION_ISOLATION_LEVEL AS VARCHAR(32))
  70. END AS TRANSACTION_ISOLATION_LEVEL_NAME,
  71.  
  72. R.USER_ID,
  73. C.CLIENT_NET_ADDRESS,
  74. ST.TEXT AS QUERY_TEXT,
  75.  
  76. -- START_OFFSET_QUERY
  77. ------ Number of characters into the currently executing batch or stored procedure at which the currently executing statement starts.
  78. R.statement_start_offset AS START_OFFSET_QUERY,
  79.  
  80. -- END_OFFSET_QUERY
  81. ------ Number of characters into the currently executing batch or stored procedure at which the currently executing statement ends.
  82. R.statement_end_offset AS END_OFFSET_QUERY,
  83.  
  84. QP.QUERY_PLAN AS XML_QUERY_PLAN,
  85.  
  86. -- PERCENT_COMPLETE
  87. ------ Percentage of work completed for the following commands:
  88. -------- ALTER INDEX REORGANIZE
  89. -------- AUTO_SHRINK option with ALTER DATABASE
  90. -------- BACKUP DATABASE
  91. -------- DBCC CHECKDB
  92. -------- DBCC CHECKFILEGROUP
  93. -------- DBCC CHECKTABLE
  94. -------- DBCC INDEXDEFRAG
  95. -------- DBCC SHRINKDATABASE
  96. -------- DBCC SHRINKFILE
  97. -------- RECOVERY
  98. -------- RESTORE DATABASE,
  99. -------- ROLLBACK
  100. -------- TDE ENCRYPTION
  101. R.PERCENT_COMPLETE
  102. FROM
  103. SYS.DM_EXEC_REQUESTS R
  104. LEFT OUTER JOIN SYS.DM_EXEC_SESSIONS S
  105. ON S.SESSION_ID = R.SESSION_ID
  106. LEFT OUTER JOIN SYS.DM_EXEC_CONNECTIONS C
  107. ON C.CONNECTION_ID = R.CONNECTION_ID
  108. CROSS APPLY SYS.DM_EXEC_SQL_TEXT(R.SQL_HANDLE) ST
  109. CROSS APPLY SYS.DM_EXEC_QUERY_PLAN(R.PLAN_HANDLE) QP
  110. WHERE
  111. R.STATUS NOT IN ('BACKGROUND', 'SLEEPING')
  112.  
  113. --KILL <SESSION_ID>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement