我的任务是创建一个将返回以下数据的查询:
[架构名称]、[对象名称]、[扩展属性名称]、[扩展属性值]
任何想法如何做到这一点?我找到了 fn_listextendedproperty 函数,但这并没有多大帮助。
我的任务是创建一个将返回以下数据的查询:
[架构名称]、[对象名称]、[扩展属性名称]、[扩展属性值]
任何想法如何做到这一点?我找到了 fn_listextendedproperty 函数,但这并没有多大帮助。
使用这个特定于列的查询:
SELECT S.name as [Schema Name], O.name AS [Object Name], ep.name, ep.value AS [Extended property]
FROM sys.extended_properties EP
INNER JOIN sys.all_objects O ON ep.major_id = O.object_id
INNER JOIN sys.schemas S on O.schema_id = S.schema_id
INNER JOIN sys.columns AS c ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
将此查询用于所有扩展属性:
SELECT S.name as [Schema Name], O.name AS [Object Name], ep.name, ep.value AS [Extended property]
FROM sys.extended_properties EP
LEFT JOIN sys.all_objects O ON ep.major_id = O.object_id
LEFT JOIN sys.schemas S on O.schema_id = S.schema_id
LEFT JOIN sys.columns AS c ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
这会带来特定对象的所有列,以及它的属性(如果存在)。
SELECT
O.name AS [Object Name],
c.name,
ep.value AS [Extended property]
FROM
sys.columns AS c INNER JOIN
sys.all_objects O ON c.object_id = O.object_id LEFT JOIN
sys.extended_properties EP ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
WHERE
O.name = 'table-name'