SqlServer 08: Query to list all databases in an instance?
How do I list all the databases for a given sql server 08 instance using sqlcmd? sqlcmd -E -S SERVER\INSTANCE -Q "sp_databases" EXEC sp_databases or SELECT NAME FROM sys.sysdatabases or EXEC sp_msForEachDB 'PRINT ''?'''; To elaborate with more detail for the sqlcmd newbie: C:\> sqlcmd -S <the_server_name> 1> select name from sys.databases 2> go You can use sp_databases stored procedure. 来源: https://stackoverflow.com/questions/2087902/sqlserver-08-query-to-list-all-databases-in-an-instance