Skip to content

Instantly share code, notes, and snippets.

@bartread
Created January 10, 2017 12:18
Show Gist options
  • Save bartread/fc33f4d0b90be2ea08221056ef8c229c to your computer and use it in GitHub Desktop.
Save bartread/fc33f4d0b90be2ea08221056ef8c229c to your computer and use it in GitHub Desktop.
Map object IDs (e.g., retrieved from SQL Profiler trace table) to qualified object names
/*
This script maps object IDs retrieved from, for example, a SQL Profiler trace table
back onto their object names.
Many SQL Profiler events, such as Scan:Stopped, collect the object ID, but do not map
it back onto an object name. If your trace table isn't on the same instance (smart)
or the database to which the event pertains (again, smart).
The IDs in this script are for the purposes of illustration only.
*/
DECLARE @objectIDs TABLE (id BIGINT NOT NULL);
INSERT INTO @objectIDs
([id])
VALUES
(1973022210),
(1950285755),
(0),
(41),
(866574799),
(75),
(197248524),
(60),
(49),
(650733795),
(2102298549),
(1696933317),
(1379535998),
(1319675749),
(925148137),
(124071728);
SELECT
[id]
, OBJECT_SCHEMA_NAME([id]) AS [Schema]
, OBJECT_NAME([id]) AS [Name]
, [QualifiedName] = OBJECT_SCHEMA_NAME([id]) + '.' + OBJECT_NAME([id])
FROM @objectIDs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment