Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 29th, 2006, 02:22 AM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Find databaseName of particular object?

Hi,

I am having nearly 10 databases in database server with more than 1000 objects. Now, i got a stored procedure written in SQL Server 2000. I am having it's name as "spGetCustomerByName".

Can anybody tell how to find the exact databasename that this stored procedure in present in?

I am using SQL Server 2000. I am not creator of database objects, so i am not confirmed about its location.

A.D.Ramkumar
__________________
Ramkumar A D
 
Old May 29th, 2006, 08:40 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a quick'n'dirty solution... Not pretty but it works!



---------------------------------------------------------------------
declare @proc_name nvarchar(100)
select @proc_name = 'uspPeriodsOpen'

create table #db (z smallint identity(0, 1), dbname nvarchar (100), present tinyint)

insert into #db (dbname)
EXEC sp_MSforeachdb @command1="select '?'"

declare @z smallint, @maxz smallint, @sql nvarchar (500), @db nvarchar (100)

select @z = 0,
@maxz = max(z)
from #db

while @z <= @maxz
   begin
select @db = quotename(dbname)
from #db
where z = @z

select @sql = 'update #db set present = (select count(*) from ' + @db + '..sysobjects where name = ''' + convert(nvarchar, @proc_name) + ''') where z = ' + convert(nvarchar, @z)

exec sp_executesql @sql

select @z = @z + 1
   end


select dbname from #db where present = 1

drop table #db
 
Old May 29th, 2006, 08:54 AM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kindly check this article for the reply:

http://www.sql-server-performance.co...se_objects.asp

A.D.Ramkumar
 
Old May 29th, 2006, 09:08 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

These are all fine scripts, but they all return the name of all databases, even of there are not match...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Box can't find Object message PaulJH Access 5 April 13th, 2007 03:27 PM
cannot resolve object, cannot find java file!!help Calverstine Apache Tomcat 3 May 22nd, 2006 03:02 PM
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM
can't find an object kliu9 Excel VBA 7 March 4th, 2005 06:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.