SQL Server 2005: How do I know if a table is being used in a stored procedure or not
April 7, 2010 Leave a comment
This is the most hectic task I have often got called for. How can I find out if a table is being used in stored procedures or not?
The easiest way to find that out is to run the following SQL. This statement searches for the table name text in all the stored procedures and returns found stored procedure names.
So, if a table is not being used in any of the stored procedure – you will get an empty resultset.
--search for ImportCustomer table
SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%ImportCustomer%'
GO
--search for ImportCustomer table and CreatedBy column
SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%ImportCustomer%'
AND OBJECT_DEFINITION(OBJECT_ID) LIKE '%CreatedBy%'