在SQL Server中获取表的描述

时间:2015-07-27 12:14:49

标签: c# sql-server

我想简单地得到表格的MS_Description

现在我只将它用于列:

select 
    sc.name, 
    sep.value [Description]
from sys.tables st
inner join sys.columns sc on st.object_id = sc.object_id
left join sys.extended_properties sep on st.object_id = sep.major_id
                                     and sc.column_id = sep.minor_id
                                     and sep.name = 'MS_Description'
where st.name =@TableName

我还有@TableName作为参数 感谢

1 个答案:

答案 0 :(得分:2)

试试这个 - 基本上使用minor_id = 0来获取表格的描述(不是任何列):

SELECT 
    t.Name, 
    sep.* 
FROM 
    sys.tables t
INNER JOIN 
    sys.extended_properties sep ON t.object_id = sep.major_id
where 
    sep.Name = 'MS_Description'
    AND sep.minor_id = 0    -- not any column - but the table's description