SQL Server Show/List Databases
Last Updated :
21 May, 2024
Listing all databases in SQL Server is a common task for database administrators and developers. SQL Server provides two main methods to solve this such as using SQL commands and using SQL Server Management Studio (SSMS). In this article, we will learn about how to Show/List the SQL Server Databases using both approaches in detail.
SHOW/LIST Databases in SQL Server
Listing all databases in SQL Server is a common task for database administrators and developers. SQL Server provides two main methods to solve this task are defined below:
- Using SQL commands
- Using SQL Server Management Studio (SSMS)
SHOW Databases using SQL commands in the Command Prompt
We can use a command prompt in our system or SQL Server Management Studio (SSMS) to execute our SQL commands. Below are the commands or queries to show databases in the SQL Server system. To connect SQL Server in the command prompt of our system we use the below command.
C:\>sqlcmd -S <hostname>\<instancename>
Output:
SQL Server connection in cmd1. Using SELECT command
The below command results in all the databases including user-databases available in the system:
SELECT name FROM sys.databases;
Output:
SQL Server databasesExplanation: SELECT statement selects the NAME of the system databases including user-created databases using SYS.DATABASES command.
We can also display only required information of databases in the system, we use the query as below:
SELECT name, database_id, create_date FROM sys.databases;
Output:

Explanation: The above query displays name, database_id, and create_date of system databases and user-created databases using SELECT and SYS.DATABASES command.
2. Using EXEC command
The other approach of listing all the databases is using EXEC command . Here the below command displays all the system and user databases.
EXEC sp_databases;
Output:
SQL Server Databases using EXECExplanation: The above query 'EXEC sp_databases' selects and displays database_name, database_size, and remarks of all the databases present in the SQL Server system.
How to get the User-Created Databases Name in SQL Server?
If we want to fetch only the names and details of user created databases, we need to execute the below query. This query filters the known system databases and displays user created ones.
SELECT name, database_id, create_date
FROM sys.databases
WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb');
Output:
user-created databasesExplanation: The above query displays name, database_id, create_date of user-created databases excluding system databases i.e,('master', 'model', 'msdb', 'tempdb').
Displaying user-created databases can also be done using the below query, where we use database_id to display databases other than 'master', 'model', 'msdb', 'tempdb'.
SELECT name, database_id FROM sys.databases
WHERE database_id > 4;
Output:
user-created databases in SQL ServerExplanation: The above query selects the user-created databases based on database_id.
SHOW Databases Using SQL Server Management Studio (SSMS)
- Microsoft SQL Server Management Studio (SSMS) is a software application developed by Microsoft that is used for configuring, managing, and administering all components within Microsoft SQL Server.
- SSMS provides a single comprehensive utility that combines a broad group of graphical tools with many rich script editors to provide access to SQL Server for developers and database administrators of all skill levels.
- Therefore SSMS is a GUI tool which provides user-friendly interface to perform several operations using both SQL commands and in-built features.
- We can use to it display all the databases without any queries or SQL commands. Here are the steps to list databases present in the SQL Server instance.
- Follow the below steps to display the databases present in the SQL Server instance:
Step 1: Install the SQL Server Management Studio (SSMS) in your system. Refer to Installation Of SSMS.
Step 2: After installation open SSMS in administrator mode and grant all the permissions required.
Step 3: Now select 'Server type' as 'Database Engine' and connect to 'Server name' followed by your directory.

Step 4: Once the connection is established, we will see 'Object Explorer' in the top left corner. Now click '+' button of 'Databases' folder which will display all the databases present in the current server instance.
Listing databases in SSMSConclusion
Overall, SQL Server offers a robust platform for managing databases, providing users with a range of tools and options for listing databases. Whether you prefer the flexibility of SQL commands or the user-friendly interface of SSMS, SQL Server caters to diverse user needs and environments. By following the techniques outlined in this article, you can efficiently navigate and manage databases in SQL Server.
Similar Reads
List All Databases in SQL Server
In SQL Server, databases are crucial for storing and managing data efficiently. Whether we are managing a large enterprise system or a small application, understanding how to list all the databases on our SQL Server is essential. In this article, we will write SQL queries that help us to retrieve al
3 min read
SQL - Show Databases
In the dynamic scene of database management, having a good insight into the available databases for effective administration and development tasks. SHOW DATABASES command is designed to present all databases located on the server. The purpose of exploring the SQL SHOW DATABASES command is to give da
3 min read
Create Database in MS SQL Server
Databases in Microsoft SQL Server are crucial for managing data, categorized into system databases, which are auto-created and user databases, created by users. In this article, We will learn about the basics of system and user databases along with methods for creating and managing them using T-SQL
6 min read
PostgreSQL - Show Databases
In PostgreSQL, viewing a list of all databases on a server requires specific commands, as it doesnât support a direct SHOW DATABASES statement like MySQL. Instead, you can use the \l or \l+ commands in psql or query the pg_database view to display all databases. In this article, we will guide us thr
3 min read
How to Show a List of Databases in PL/SQL?
Managing databases is a fundamental aspect of database administration and development. In Oracle Database, schemas represent logical containers for database objects like tables, views, procedures, and functions. PL/SQL is the procedural extension of and used in Oracle Database and provides powerful
5 min read
How to Show Database in PL/SQL
PL/SQL is the Procedural Language/Structured Query Language and serves as a procedural language built-in extension to SQL language, which allows seamless integration of procedural constructs with SQL. One of the most common functions of a DBMS is the retrieval of information about databases which is
4 min read
SQL Select Database
The USE DATABASE statement is a command in certain SQL-based database management systems that allows users to select and set a specific database as the default for the current session. By selecting a database, subsequent queries are executed within the context of that database, making it easier to i
4 min read
How to Open a Database in SQL Server?
Opening a database in SQL Server is a fundamental task for database administrators and developers. It involves establishing a connection to the server instance and selecting a database to work with. In this article, we will explore two methods to open a database in SQL Server such as using SQL Serve
3 min read
SQL DROP DATABASE
The SQL DROP DATABASE statement is an important command used to permanently delete a database from the Database Management System (DBMS). When executed, this command removes the database and all its associated objects, including tables, views, stored procedures, and other entities. In this article,
4 min read
Interface Python with an SQL Database
Python is an easy-to-learn language and connectivity of python with any SQL database is a much-desired option to have the persistence feature. Python is an object-oriented programming language and it is open source. Newcomers to the software industry including school children too can learn Python ea
8 min read