views:

347

answers:

2

I can use select * from sys.tables in mssql to show a list of all tables in the current database. Is there anyways I can use similar syntax to show list of tables in another database?

Say I am using A with use A statement, can I show tables in database B?

+10  A: 

This does it for me (MS SQL 2005 and newer):

select * from your_database_name.sys.tables

Keep in mind that you (or whatever authentication context you're using) will still need read permission on that database.

To use your example:

use a;
go

select * from sys.tables; -- selects table info from a
select * from b.sys.tables; -- selects table info from b
Daniel Schaffer
good job thank you very much
Haoest
The question and answer should be clarified as being applicable to MS-SQL 2005 and newer.
Peter LaComb Jr.
A: 

Another possibility is to use:

select * from your_database_name.information_schema.tables
Gudmundur Orn