How do you display a list of tables in another database?

I can use:

select * from sys.tables

      

in mssql to list all tables in the current database. Is there anyway I can use a similar syntax to display a list of tables in another database?

Let's say I am using A with:

use A

      

can i show tables in database B?

+9


source to share


2 answers


This is for me (MS SQL 2005 and newer):

select * from your_database_name.sys.tables

      

Be aware that you (or whatever authentication context you are using) still needs read permission on this 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

      

+16


source


Another possibility is to use:



select * from your_database_name.information_schema.tables

      

0


source







All Articles