查询所有表及注释
SELECT so.name ,
ep.[value] AS [description]
FROM sysobjects so ( NOLOCK )
LEFT JOIN sys.extended_properties ep ( NOLOCK ) ON ep.major_id = so.id
AND ep.minor_id = 0
WHERE so.[type] = 'U'
ORDER BY so.name
查询表中所有字段及注释
SELECT c.name ,
t.name AS [type] ,
c.max_length AS maxLength ,
c.is_nullable AS isNullable ,
( SELECT COUNT(1)
FROM sys.identity_columns ic ( NOLOCK )
WHERE ic.[object_id] = c.[object_id]
AND ic.column_id = c.column_id
) AS isIdentity ,
( SELECT VALUE
FROM sys.extended_properties ep ( NOLOCK )
WHERE ep.major_id = c.object_id
AND ep.minor_id = c.column_id
) AS [description]
FROM sys.[columns] c ( NOLOCK )
INNER JOIN sys.tables ts ( NOLOCK ) ON ts.[object_id] = c.[object_id]
INNER JOIN sys.types t ( NOLOCK ) ON t.system_type_id = c.system_type_id
INNER JOIN systypes st ( NOLOCK ) ON st.name = t.name
AND st.name <> 'sysname'
INNER JOIN sysusers su ( NOLOCK ) ON st.uid = su.uid
AND su.name = 'sys'
WHERE ts.name = 'Question'
ORDER BY c.column_id ASC