I have an application that queries and updates two databases at the same time (different from each other) and it has already around 10 to 15 years of usage. So I would like to start clearing up the garbage from them.
One of the things that I want to do is to remove all the stored procedures that are in database B that by mistake were created there (because they had to go in database A).
If I do one by one, is easy because I can tell if the sp uses a table that is not in that database. But I bet there are many of them, so I want to get a query that validates this.
This is the link from microsoft that explains this: http://msdn.microsoft.com/en-us/library/ms190686.aspx. But it doesn't give me any solution! :S
I tried the below method: http://beyondrelational.com/blogs/jacob/archive/2009/01/28/tsql-how-to-revalidate-refresh-recompile-all-stored-procedures-in-a-database.aspx
But it worked for some, but not for all.
So do you guys know any effective method that will work 100% of the time? Tryouts:
- Recompilation > NOT
- sp_refreshsqlmodule > works for most, but not all
- sp_depends > it may work since all the SPs need to have a dependency on a table (at least most of them). UPDATE: This doesn't work either. If I have a sp that looks for tables in both databases, it will resolve those that can, but not all. So I can't rely on "if no dependencies, candidate to delete".
Thanks in advance