Sqlserver
 SQL >> Database >  >> RDS >> Sqlserver

Tre modi per trovare le dipendenze di una tabella SQL Server

Ecco gli approcci che userei:

Metodo 1: sp_depends

 sp_depends 'dbo.First' GO 

Metodo 2: information_schema.routines

 SELECT * FROM information_schema.routines ISR WHERE CHARINDEX('dbo.First', ISR.ROUTINE_DEFINITION) > 0 GO 

Metodo 3: la DMV sys.dm_sql_referencing_entities

 SELECT referencing_schema_name, referencing_entity_name, referencing_id, referencing_class_desc, is_caller_dependent FROM sys.dm_sql_referencing_entities ('dbo.First', 'OBJECT'); GO 

Una parola di cautela: sp_depends è deprecato e notoriamente inaffidabile, poiché riflette le dipendenze solo al momento della creazione. La DMV del metodo 3 è la più affidabile delle tre.