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

前端 未结 10 1797
终归单人心
终归单人心 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:18

    Try more elegant way (but, it's solution works only in MS SQL 2008 or higher) -

    SELECT DISTINCT 
          [object_name] = SCHEMA_NAME(o.[schema_id]) + '.' + o.name
        , o.type_desc
    FROM sys.dm_sql_referenced_entities ('dbo.usp_test1', 'OBJECT') d
    JOIN sys.objects o ON d.referenced_id = o.[object_id]
    WHERE o.[type] IN ('U', 'V')
    

提交回复
热议问题