📜  T-SQL - Where Used 列表(表视图) - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:22.304000             🧑  作者: Mango

代码示例1
select schema_name(o.schema_id) + '.' + o.name as [table],
       'is used by' as ref,
       schema_name(ref_o.schema_id) + '.' + ref_o.name as [object],
       ref_o.type_desc as object_type
from sys.objects o
join sys.sql_expression_dependencies dep
     on o.object_id = dep.referenced_id
join sys.objects ref_o
     on dep.referencing_id = ref_o.object_id
where o.type in ('V', 'U')
      and schema_name(o.schema_id) = 'Person'  -- put schema name here
      and o.name = 'Person'   -- put table/view name here
order by [object]