SQL Query To List All Databases

Chapter: SQL Commands Last Updated: 17-04-2023 13:41:36 UTC

Program:

            /* ............... START ............... */
                
SELECT name FROM master.sys.databases;

                /* ............... END ............... */
        

Output

--Sample output

name
--------------------
master
tempdb
model
msdb
AdventureWorks
AdventureWorksDW

Notes:

  • The SQL Server instance can have multiple databases, each of which may contain tables, views, stored procedures, and other database objects.
  • To list all databases on a SQL Server instance, you can use the master.sys.databases system view, which contains a row for each database on the server.
  • The name column of the master.sys.databases view contains the name of the database.
  • To query the master.sys.databases view, you will need appropriate permissions on the SQL Server instance. Typically, the VIEW ANY DATABASE permission is required.
  • Depending on your specific requirements, you may need to filter the list of databases returned by the query. For example, you could add a WHERE clause to the query to filter by a specific database name, or you could use a wildcard to search for databases that match a pattern.

Tags

How to Show a List of Databases in SQL #SQL Query To List All Databases

Similar Programs Chapter Last Updated
SQL Query To Find Duplicate Records SQL Commands 17-04-2023
How To Create Procedure In SQL SQL Commands 24-03-2023
Group By In SQL SQL Commands 12-11-2020
Substring In SQL SQL Commands 27-11-2019
SQL SELECT Statement SQL Commands 16-03-2018

1