Find the database by table name

,

Here's the scenario:
1.  You have been given a script to run.
2.  You do not know the database name.
3.  You know which server.

Substitute the word "TABLENAME" with the table name in the script and run in query analyzer.  This query will check every database on the server and return the name of the database with the requested table name. 

exec master.dbo.sp_msforeachdb 
"USE [?] 
select	db_name()
from	sysobjects
where	name = 'TABLENAME'
"

Rate

2 (1)

Share

Share

Rate

2 (1)