What is Script to find the list of stored procedures in all databases?
I want to pull out the list of stored procedures which are available in my instance. I used the following T-SQL statement to get the stored procedures in a given database. select * from MyDatabase.information_schema.routines where routine_type = 'Procedure' Is there is any script to obtain the all stored procedures or to check the database name of the stored procedure by using the stored procedure name? What is sql server search stored procedures?
SQL server search stored procedures A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it. You can use the following code for SQL server search stored procedures: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
The code above runs a USE and then a SELECT from sys.procedures for each database, loading the data into a temp table. sys.procedures lists out all of the stored procedures in the database and sp_msforeachdb will run the code on each database (use a ? for the databasename in the code). Once the code is run you can query the temp table to get the consolidated list. sp_msforeachdb is known to have issues so you may want to use Aaron Bertrand's improved version located here.