Skip to content

Instantly share code, notes, and snippets.

@keithbloom
Created February 20, 2012 13:41
Show Gist options
  • Save keithbloom/1869246 to your computer and use it in GitHub Desktop.
Save keithbloom/1869246 to your computer and use it in GitHub Desktop.
Using Extended Properties to limit the call to sp_msforeachtable
SELECT s.name [Schema], t.name [Table],
CAST(Value AS nvarchar(500)) AS [MS_Description]
FROM sys.extended_properties AS ep
JOIN sys.tables t
on ep.major_id = t.object_id
join sys.schemas s
on s.schema_id = t.schema_id
WHERE ep.name = N'MS_Description' AND ep.minor_id = 0
and LOWER(CAST(Value AS nvarchar(500))) like '%lookup%'
order by s.name, t.name
USE AdventureWorks
GO
EXEC sp_msforeachtable @command1 = 'EXECUTE sp_spaceused [?];'
,@whereand = 'AND o.id in (
SELECT ep.major_id
FROM sys.extended_properties AS ep
WHERE LOWER(CAST(Value AS nvarchar(500))) LIKE ''%lookup%''
AND ep.name = N''MS_Description''
AND ep.minor_id = 0)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment