Wednesday, December 22, 2010

Where is my table?

Where is my table?

I find it really annoying that users create tables with same name in multiple databases in development and sometimes production environment. They one fine day they compare the tables in and find the data different. This creates a big problem for DBAs figuring out what all places table exists. So here is a small script to do just that

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

1 comment:

  1. Hey Yogesh,

    Among all information this one is very fine and more useful.

    Bharath|SQL DBA|Esurance,inc|Offshore