How to take list of databases in SQL Server

In SQLCMD and Powershell I wanted to take the list of databases. In MySQL “show databases” command was there. But in SQLCMD I was unable to find such a command.

nn

--Stored ProcedurenEXEC sp_databases  nGO   n  n--SELECT StatementnSELECT Name FROM master.dbo.sysdatabases  nGO n

nn

You can use the above commands in SSMS (if you are lazy to move your mouse to object explorer) and SQLCMD. Also, you can use the same thing on PowerShell too.

nn

# Stored ProcedurenInvoke-SQLCMD "EXEC sp\_databases"  nn# SELECT StatementnInvoke-SQLCMD "SELECT Name FROM master.dbo.sysdatabases"n

nn

But in SQLPS you can go to your SQL Server instance’s database and just type “dir”.

nn

Tags

nn

    n

  • SQL
  • n

  • SQLPS
  • n

  • Powershell
  • n

  • Administration
  • n

  • SQLCMD
  • n

  • SQL Server
  • n

  • SQL Sever
  • n

n

Proudly powered by WordPress

Discover more from Dedunu

Subscribe now to keep reading and get access to the full archive.

Continue reading