Labels

Friday, December 30, 2011

extended properties for table columns

SELECT
ObjecType   = objtype,
ObjectName  = objname,
Name        = name,
Value       = value
FROM fn_listextendedproperty (NULL, 'schema', 'Production',
'table', 'Product', 'column', default);
              GO


list all columns with extended properties:

SELECT   [Schema] = s.name,
         [Table] = object_name(major_id),
         [Column] = c.name,
         [Type] = t.name,
         [Extended] = p.VALUE
FROM     sys.extended_properties p
         JOIN sys.columns c
           ON c.column_id = p.minor_id 
              AND c.object_id = p.major_id
         JOIN sys.objects o
           ON o.object_id = p.major_id
              AND o.object_id = c.object_id
         JOIN sys.schemas s
           ON s.schema_id = o.schema_id
         JOIN sys.types t
           ON c.system_type_id = t.user_type_id
WHERE    o.TYPE = 'U'
         AND class_desc = 'OBJECT_OR_COLUMN'
ORDER BY [Schema],
         [Table],
         c.column_id

No comments:

Post a Comment