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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With