Please help me on this issue. I have a specific table from a specific database. I want to find the stored procedure using the table from all databases available.
1 Answer
For this, I would use Aaron Bertrand's improved sp_msforeachdb
EXECUTE sp_foreachdb @command = N'SELECT * FROM ?.sys.sql_modules AS sm WHERE sm.Definition LIKE ''%dbo.YourTable%''' , @user_only = 1 The @command is necessary, but I added the @user_only to show that you can skip system databases. If you do want to check them, remove this parameter.
I recommend Aaron's solution over sp_msforeachdb because it is unsupported, and as he mentions in his blog, it can miss databases under heavy load.