Technical Article

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 [?] 
selectdb_name()
fromsysobjects
wherename = 'TABLENAME'
"

Rate

2 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

2 (1)

You rated this post out of 5. Change rating