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