databasestored-procedures

How do I get a list of tables affected by a set of stored procedures?


I have a huge database with some 100 tables and some 250 stored procedures. I want to know the list of tables affected by a subset of stored procedures. For example, I have a list of 50 stored procedures, out of 250, and I want to know the list of tables that will be affected by these 50 stored procedures. Is there any easy way for doing this, other than reading all the stored procedures and finding the list of tables manually?

PS: I am using SQL Server 2000 and SQL Server 2005 clients for this.


Solution

  • This would be your SQL Server query:

    SELECT
        [NAME]
    FROM
        sysobjects
    WHERE
        xType = 'U' AND --specifies a user table object
        id in
        (
            SELECT 
                sd.depid 
            FROM 
                sysobjects so,
                sysdepends sd
            WHERE
                so.name = 'NameOfStoredProcedure' AND 
                sd.id = so.id
        )
    

    Hope this helps someone.