Created
January 10, 2017 17:36
-
-
Save bartread/3c904ab47337c5905e0159f9d865cba2 to your computer and use it in GitHub Desktop.
Maps activity in tempdb over a given time period to events in SQL Profiler trace by Transaction ID to allow you to relate tempdb activity to activity in other databases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This query allows you to relate activity in tempdb to activity in other databases | |
where that activity has been recorded in a SQL Profiler trace table. | |
This can come in useful when, for example, diagnosing the source of I/O activity | |
and possible bottlenecking in tempdb. | |
*/ | |
SELECT d.TransactionID, | |
d.RowNumber, | |
d.StartTime, | |
d.EndTime, | |
te.name as EventType, | |
d.DatabaseName, | |
d.ApplicationName, | |
d.NTUserName, | |
d.LoginName, | |
d.TextData, | |
d.HostName, | |
d.ObjectName, | |
d.ObjectID, | |
d.CPU, | |
d.Reads, | |
d.Writes, | |
d.SPID, | |
[DurationMillis] = d.Duration / 1000 | |
FROM | |
( | |
SELECT DISTINCT d2.TransactionId | |
FROM [YOUR_TRACE_SCHEMA_NAME].[YOUR_TRACE_TABLE_NAME] AS d2 -- Substitute your trace table name here. | |
WHERE | |
d2.StartTime >= '2017-01-10 11:50:00.000' | |
AND d2.StartTime <= '2017-01-10 11:56:00.000' | |
AND d2.DatabaseName = 'tempdb' | |
) AS ti | |
INNER JOIN [YOUR_TRACE_SCHEMA_NAME].[YOUR_TRACE_TABLE_NAME] AS d -- Substitute your trace table name here. | |
ON d.TransactionID = ti.TransactionID | |
INNER JOIN sys.trace_events AS te | |
ON te.trace_event_id = d.EventClass | |
ORDER BY | |
d.TransactionID ASC, | |
d.RowNumber ASC | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment