Technical Article

Get list of tables used in a stored procedure

,

It used to find the table dependencies, helps the developers during an enhancement stage to find the tables are used in a stored procedure.

/*
  Get the DB Tables used in a Stored Procedure  
  It used from sysdepends, sysobjects table to gather information
  It may not be accurate if the DB is not refreshed
  
*/SELECT DISTINCT
 o.id, o.name as 'Procedure_Name' , oo.name as 'Table_Name', d.depid, d.depnumber 
FROM sysdepends d, sysobjects o, sysobjects oo
WHERE o.id=d.id 
and o.name= 'CustOrdersDetail'   -- Stored Procedure Name
and oo.id=d.depid and depnumber=1
ORDER BY o.name,oo.name

Rate

4.29 (7)

You rated this post out of 5. Change rating

Share

Share

Rate

4.29 (7)

You rated this post out of 5. Change rating