SqlServer 08: Query to list all databases in an instance?

sqlcmd -E -S SERVER\INSTANCE -Q "sp_databases"

Notes:

  • -E: Use a trusted connection (“Windows authentication”). Replace by -U username -P password for SQL Server authentication.
  • -S SERVER\INSTANCE: The instance of SQL Server to which to connect. If you don’t know the name of your instance, you can use sqlcmd -L to get a list.
  • -Q: The query to execute. The uppercase Q causes sqlcmd to exit after executing the query.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)