Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Find the tables used in a SP

$
0
0

Example:
Create proc SQL
AS
Begin  

CREATE TABLE #temp

      (

         Name varchar(14),

         Num varchar(9),

         SSN varchar(9),

         req int,

         VN varchar(12),

         PayrunDt smalldatetime,

         UpdateDt smalldatetime

      )
      INSERT #temp

         SELECT DISTINCT

            a.Name ,

            a.Num ,

            a.SSN,

            a.req ,

            c.VN ,

            b.PayRunDt,

            d.UpdateDt

         FROM

            dbo.Trv  AS a,

            dbo.Ver  AS b,

            dbo.VTrv  AS c,

            dbo.TrvVs  AS d

where a.id=b.id and b.id=c.id and c.id=d.id

Select * from #temp

END

Question :I have X numbers of SP as shown in the above example(with different select queries loading data to x number of temp tables). i have to find the table and columns involved in the SP. can you please help me with the query? so that i can use it to for other SP's?

tried using the below Q, no luck

SELECT DISTINCT
 SP_Name = O.name,
 Table_Name = OO.name
 FROM sys.sysdepends D INNER JOIN sys.sysobjects O ON
 O.id = D.id
 INNER JOIN sys.sysobjects OO ON
 OO.id = D.depid
 WHERE O.xtype = 'P' and o.name in ('sp names')



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>