1

I'd like to know if there is any way to search for a procedure in all the databases of a server (there are only SQL Server databases on that server).

So far I've only found how to find a stored procedure in a certain database with Object_id(), but it would take too long for me to manually search each database by hand. I'd also like to see in which database is the stored procedure applied.

Code I've found so far:

select * 
from MyDataBase.sys.objects 
where object_id = object_id(N'MyProcedure')
2

1 Answer 1

2

You can try this code

CREATE TABLE #SPs (db_name varchar(100), name varchar(100), object_id int)

EXEC sp_msforeachdb 'USE [?]; INSERT INTO #SPs select ''?'', name, object_id from sys.procedures'

SELECT * FROM #SPs

See also :https://dba.stackexchange.com/questions/130399/script-to-find-the-list-of-stored-procedures-in-all-databases

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.