Find Out Table and Function Used in Procedure

  1.  WITH cte   
  2. AS  
  3. (  
  4.     SELECT  
  5.         source.name AS source,   
  6.         target.name AS target,  
  7.         CASE target.xtype   
  8.             WHEN 'U'  THEN 'Table'  
  9.             WHEN 'P'  THEN 'Store Procedure'  
  10.             WHEN 'FN' THEN 'Function'  
  11.             WHEN 'V'  THEN 'View'  
  12.         END AS type  
  13.     FROM sysdepends d   
  14.     INNER JOIN sysobjects source ON source.id = d.id  
  15.     INNER JOIN sysobjects target ON target.id = d.depid  
  16.     WHERE source.xtype = 'P' and source.name='PAYSP_EMPLOYEEUSERLOGINCHECK'  
  17. )  
  18. SELECT DISTINCT target, source, type  
  19. FROM cte  
  20. ORDER BY target, type DESC, source