The fn_listextendedproperty
system function will do what you're looking for.
It’s also referred to as sys.fn_listextendedproperty
.
Syntax is as follows:
fn_listextendedproperty (
{ default | 'property_name' | NULL }
, { default | 'level0_object_type' | NULL }
, { default | 'level0_object_name' | NULL }
, { default | 'level1_object_type' | NULL }
, { default | 'level1_object_name' | NULL }
, { default | 'level2_object_type' | NULL }
, { default | 'level2_object_name' | NULL }
)
Example Usage: Lists extended properties for all columns of the ScrapReason
table in the Production
schema
USE AdventureWorks2012;
GO
SELECT objtype, objname, name, value
FROM fn_listextendedproperty (NULL, 'schema', 'Production', 'table', 'ScrapReason', 'column', NULL);
GO
sp_helptext
will not work since it can't be used for tables as per TechNet.
Displays the definition of a user-defined rule, default, unencrypted
Transact-SQL stored procedure, user-defined Transact-SQL function,
trigger, computed column, CHECK constraint, view, or system object
such as a system stored procedure.
sp_columns
does not return the sys.extended_properties.value
field which you're looking for.
fn_listextendedproperty
is arguably easier to work with and more generic than the query in the accepted answer.