Is there a t-sql script to find out tables that aren’t being used in sql server by stored procudures, views, functions, etc. I have a database that has 100s of tables, if not more and before I go dropping tables, I wanted to know if there was a script that could go through each object in the database and tell me if any tables are in use.
Share
If you want using a script, here (Listing SQL Server Object Dependencies) is a very good article how to script dependencies. Using that, you can make a list of tables being referenced. You have the list of tables that are in your database, so you know which of them are not being used.
In the article they use
stored procedure. However it has one failure. For example, if you have a stored procedure that used table “MyTable” and you create the procedure before you create the table “MyTable” you won’t see this on the list of dependencies. That’s why you should search the table
to find dependencies. But this is also not accurate, because if you have the name of the table in the comment, you will treat it as a dependency.