Saturday, May 28, 2011

Powerful database query to know the database name if you know the table name

SQL server has a powerful feature to know the database name when we give table name.
The below is the query

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