views:

520

answers:

3

I exported a table to a server but I can't find the table. Maybe I didn't put the right destination database. How can I find this table if my server has multiple databases, without opening each one of them?

I use MS Sql Server Management Studio 2008.

A: 
select 'select * from '+name+'.sys.tables where name=
        ''[yourtable]'';' from sys.databases

Instead of [yourtable], type the name of the missing table, and run the result again.

cdonner
+3  A: 

Rough and dirty, but it would do the job.

sp_MSforeachdb 'USE ?
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N''[table_name_here]'') AND OBJECTPROPERTY(id, N''IsUserTable'') = 1)
BEGIN
  PRINT ''Found in db ?''
END'
+1 for using sp_MSforeachdb, which I did not know.
cdonner
This is when you find out that two years of SQL Server support can be useful :)
A: 
EXEC sp_MSForEachDB '
USE ? 
IF OBJECT_ID(''mytable'') IS NOT NULL AND
   OBJECTPROPERTY(OBJECT_ID(''mytable''), ''IsTable'') = 1
    PRINT ''?''
'
gbn