是否可以使用connection.getschema()从sql server表列中检索描述项,就像可以检索列名,数据类型,可以为空,列默认值等一样?如果是这样,怎么样?
答案 0 :(得分:2)
试试这个:
SELECT
[Table Name] = i_s.TABLE_NAME,
[Column Name] = i_s.COLUMN_NAME,
[Description] = s.value
FROM
INFORMATION_SCHEMA.COLUMNS i_s
LEFT OUTER JOIN
sys.extended_properties s
ON
s.major_id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME)
AND s.minor_id = i_s.ORDINAL_POSITION
AND s.name = 'MS_Description'
WHERE
OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0
--AND i_s.TABLE_NAME = 'table_name'
ORDER BY
i_s.TABLE_NAME, i_s.ORDINAL_POSITION
编辑:修复查询: - )
HTH
答案 1 :(得分:1)
在Sql Server 2005上,您可以使用此系统表值函数:
fn_listextendedproperty (Transact-SQL)
或尝试查询from from this article,如下所示:
SELECT
[Table Name] = OBJECT_NAME(c.object_id),
[Column Name] = c.name,
[Description] = ex.value
FROM
sys.columns c
LEFT OUTER JOIN
sys.extended_properties ex
ON
ex.major_id = c.object_id
AND ex.minor_id = c.column_id
AND ex.name = 'MS_Description'
WHERE
OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0
-- AND OBJECT_NAME(c.object_id) = 'your_table'
ORDER
BY OBJECT_NAME(c.object_id), c.column_id
答案 2 :(得分:0)
如果您已经拥有DataTable,请查看其数据列!
foreach(DataColumn col in dataTable.Columns)
{
// check out all the properties on the DataColumn
}
这是否包含您需要的内容?