Facebook Twitter Sign in | Join

			Connect your existing Source Control system to SSMS in 5 minutes
Getting started with SSIS - Part 1: Introduction to SSIS
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Connect your existing Source Control system to SSMS in 5 minutes
Sponsored [Advertise Here]
Learn XSD and XML Schema Collections
beyondrelational.com
This book helps you to learn XML Schema Collections from basic to advanced levels through simple examples and easy to follow walk through labs.

Syndicate your blog!
beyondrelational.com
Syndicate your blog with us to get wider reach into the technology community. Click here to get started.

SSRS Tutorial - Getting Started with SQL Server Reporting Services
beyondrelational.com
This tutorial will help you to get started with SQL Server Reporting Services (SSRS)
Loading

Search Procedure name in all databases

Often I see people asking questions in the forums about finding the database name where the particular procedure exists
You can use many methods to get a solution (cursor, undocumented procedure,dynamic sql,etc)

The simplest are

1 Use Undocumented procedure

 
EXEC sp_msforeachdb 
'if exists(select ''?'' from ?.sys.objects where name=''your_procedure_name'')
select ''?'' from ?.sys.objects where name=''your_procedure_name'''

2 Use Dynamic SQL

 
declare @sql varchar(max)

set @sql= ''

select 
	@sql=@sql+' select '''+name+''' as database_name from '+name+'.sys.objects where name =''procedure_name'' union all' from sys.databases 

select @sql=substring(@sql,1,len(@sql)-9)

exec(@sql)

Note that method 1 is not recommedted as it uses undocumented stored procedure sp_msforeachdb
which may be removed from future release of the SQL Server.

Also refer this post
http://beyondrelational.com/blogs/madhivanan/archive/2008/05/13/simulating-undocumented-procedures.aspx


Madhivanan
3 · 34% · 5789
2
Liked
0
Comments



Submit

     

Subscribe to Notifications

Your Comment


Sign Up or Login to post a comment.

Copyright © Beyondrelational.com