SQL Query to find database name if you know only table name
This query is usefull when you wanted to know the database name by passing the table name.
Some situations you will not remember the database name but you remember the table name. I was thinking what we will do in such cases!!!
Don't worry Microsoft has solution for it.
You can use below query to find out the database name. Just replace the table name in place of tbl_login
exec master.dbo.sp_msforeachdb
"USE [?]
select db_name()
from sysobjects
where name = 'tbl_login'"