How to locate a table by table name

From MyWiki
Jump to: navigation, search
CREATE TABLE #t (
    DBName sysname NOT NULL
)
GO
EXEC sp_msforeachdb 'use [?]; if OBJECT_ID(''dbo.staff'') is not null insert into #t (DBName) select ''?'''
GO
SELECT * FROM #t
GO
DROP TABLE #t