?
Solved

Find database that have a specific stored proc

Posted on 2012-12-26
3
Medium Priority
?
215 Views
Last Modified: 2012-12-27
I need a line of SQL that will return only the databases on my SQL Server instance that have a specific stored procedure defined.   If the proc is named "sp_custom_proc", how would I enumerate all the databases where that proc is defined?
0
Comment
Question by:GreggPeele
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 381 total points
ID: 38722479
This will do it, but you will get a row back for each database it searches with a null result for those it doesn't find.   If you do output to text instead of grid, you can turn column headings off in Tools / Options / Query Results / SQL Server / Output to Text.

Also. sp_MSForEachDB is unsupported as far as I know, but it gets the job done.

EXEC dbo.sp_MSforeachdb 'USE [?]; SELECT SPECIFIC_CATALOG from ?.INFORMATION_SCHEMA.ROUTINES WHERE SPECIFIC_NAME = ''sp_custom_proc''';

Open in new window

0
 
LVL 21

Accepted Solution

by:
Alpesh Patel earned 384 total points
ID: 38722768
EXEC dbo.sp_MSforeachdb  'USE [?]; IF exists (select 1 from sys.procedures where name like ''EZL_AVST'') select db_name(db_id())'
0
 

Author Closing Comment

by:GreggPeele
ID: 38723580
Another option...

CREATE TABLE #x(db varchar(30), obj SYSNAME);
 
EXEC sp_msforeachdb
       @command1 ='INSERT #x SELECT ''?'',name
               FROM ?.sys.procedures
               WHERE name =''PX_ReleaseBOL37'';';
     
SELECT * FROM #x;
 
DROP TABLE #x;
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question