SqlServer 08: Query to list all databases in an instance?
-
21-09-2019 - |
Question
How do I list all the databases for a given sql server 08 instance using sqlcmd?
Solution
sqlcmd -E -S SERVER\INSTANCE -Q "sp_databases"
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow