Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 list all database names where a table resides

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-01-06 : 08:17:19
Srividya writes "Is there any specific command to get the table name as paramater and list all the database names that contains the table specified. I need a command similar to the oracle all_user_tables that gives informations about all the tables in that domain. "

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-01-06 : 08:23:34
This should work:

CREATE PROCEDURE FindTable @tbl sysname AS
SET NOCOUNT ON
CREATE TABLE #dbs(dbname sysname)
EXEC sp_MSForEachDB ''INSERT INTO #dbs(dbname) SELECT TABLE_CATALOG FROM .INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=''' + @tbl + ''''
SELECT * FROM #dbs
DROP TABLE #dbs
Go to Top of Page
   

- Advertisement -