Sunday, December 01, 2024

How to find specific table or view is used in SQL Server database

Here is how we can find a table or view in SQL database. Below query will help you find the table or view and which object has used.

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) = 'dbo'  -- put schema name here
      and 
	  o.name = 'AI_Asset_Info'   -- put table/view name here
order by [object]
  

Hope this helps!

No comments:

Post a Comment