Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

engitech@oceanthemes.net

+1 -800-456-478-23

Query

Identificar tabelas utilizadas em uma Stored Procedure

A dica de hoje é referente a uma query para identificar quais são as tabelas envolvidas em uma Stored Procedure.


SELECT DISTINCT 
	   db_name() AS [Database] ,
       O.[Name]  AS [StoredProcedure_Name],
       Oj.[Name] AS [Table_Name]
FROM sys.sql_dependencies AS D
INNER JOIN sys.objects AS O  ON  O.[object_id] = D.[object_id]
INNER JOIN sys.schemas AS S  ON  S.[schema_id] = O.[schema_id]
INNER JOIN sys.objects AS Oj ON Oj.[object_id] = D.[referenced_major_id]
INNER JOIN sys.schemas AS Sc ON Sc.[schema_id] = Oj.[schema_id]
WHERE O.[type] = 'P'
  AND Oj.[type] IN ('V','U')
  AND O.[Name] = 'sp_transfsaldosctb' --- nome da procedure.

Na imagem abaixo temos quais as tabelas que fazem parte do código da Stored Procedure “sp_transfsaldosctb” .

Author

Wesley Cardoso