Last active
April 14, 2022 13:03
-
-
Save dlgombert/875331abe035724cda2ae04369379959 to your computer and use it in GitHub Desktop.
[tables in sp] Gets tables referenced in stored procedure #tsql #sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Replace {{stored_procedure_name}} with Stored procedure name | |
| DECLARE | |
| @sp nvarchar(100) | |
| SET @sp = N'{{stored_procedure_name}}' | |
| -- Objects that depends on [@sp] | |
| SELECT | |
| referencing_entity_name | |
| FROM sys.dm_sql_referencing_entities(@sp, 'OBJECT') | |
| -- Objects on which [@sp] depends | |
| SELECT DISTINCT | |
| referenced_entity_name | |
| FROM sys.dm_sql_referenced_entities(@sp, 'OBJECT') | |
| SELECT DISTINCT | |
| referenced_entity_name | |
| FROM sys.sql_expression_dependencies | |
| WHERE referencing_id = OBJECT_ID(@sp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment