Search code examples
sql-serversql-server-2016database-schema

Get table description via SQL query


Using Microsoft SQL Server 2016, how do I query the table description property via SQL? I'm doing some class generation automation and that's the last piece that I can't figure out. It was, surprisingly to me at least, not on the sys.tables table.


Solution

  • SELECT t.name, CONVERT(VARCHAR(MAX), p.value)
    FROM sys.tables t
    JOIN sys.extended_properties p ON t.object_id = p.major_id
    WHERE t.type_desc = 'USER_TABLE' AND p.name = 'MS_Description' AND p.minor_id = 0 AND LEN(CONVERT(VARCHAR(MAX), p.value)) > 0