我为 SQL Server 2012 调整了上面的查询(谢谢@gvee)。
select o.name, ref.name, refc.name, *
from sys.sql_expression_dependencies d
inner join sys.objects o on o.object_id = d.referencing_id
inner join sys.objects ref on d.referenced_id = ref.object_id
left outer join sys.columns refc
on d.referenced_id = refc.object_id
and d.referenced_minor_id = refc.column_id
order by 1, 2, 3
select o.name, OBJECT_SCHEMA_NAME(o.object_id), *
from sys.objects o
where o.type = 'P' and o.name not in ('sp_upgraddiagrams')
and not exists (
select 1
from sys.dm_sql_referenced_entities(
OBJECT_SCHEMA_NAME(o.object_id) + '.' + o.name, 'OBJECT')
where is_updated = 1
)
order by 1
请注意,sys.dm_sql_referenced_entities
不会返回is_updated
SQL 2008 中的列。
查询sp_upgraddiagrams
会引发错误,但仍会返回结果集。