How can i get the list of tables in the stored procedure

前端 未结 10 1807
终归单人心
终归单人心 2020-12-01 05:16

There are lot of tables and sp in the db. I find the tables name which are used in the specific sp (stored procedure).

sp_depends %sp_name% not give the

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 06:07

    KyleMit's answer is using a table that will be deprecated soon as well. It is recommended to use sys.sql_experssion_dependencies instead of sys.sql_dependencies, e.g.,

    SELECT DISTINCT p.name AS proc_name, t.name AS table_name
    FROM sys.sql_expression_dependencies d
    INNER JOIN sys.procedures p ON p.object_id = d.referencing_id
    INNER JOIN sys.tables t     ON t.object_id = d.referenced_id
    ORDER BY proc_name, table_name
    

    This should work with SQL Server 2008+.

    I did not have a high enough reputation to comment directly on the referenced answer.

提交回复
热议问题