Popular Posts

Monday, November 28, 2011

SQL Server: Query to find the tables being used in a stored procedure

The query below gets the list of tables that are being referenced in a stored procedure:




SELECT DISTINCT
                 o.id, o.name AS 'Procedure_Name' , oo.name AS 'Table_Name', d.depid
FROM sysdepends d, sysobjects o, sysobjects oo
WHERE   o.id=d.id 
                AND o.name= 'usp_your_sp_here'   -- Stored Procedure Name
                AND oo.id=d.depid 
                
ORDER BY o.name,oo.name

No comments:

Post a Comment

Total Pageviews