Search for a table in all the databases

This post is in response to the question posted by $sammy! on my last post. He wanted to know how to find out the database name and the file group by having only the table name. Here is one of the scripts which I mostly use to get this information.

exec sp_MSforeachdb
'use [?]
select 
db_name()as DBName,
object_name(i.id) as TableName,
fg.groupname as FileGroup
from sysfilegroups fg, sysindexes i
where i.id =object_id(''TableNameHere'')
and i.indid < 2
and i.groupid = fg.groupid'

2 thoughts on “Search for a table in all the databases

  1. Pingback: How to: Search for a Table in All The Databases | Wisdom Soup

Comments are closed.