Finding database name in SQL servers is a daily task for an SQL developer. In this article, I will guide you through multiple ways to find a database name in SQL server with some real-time examples.
How To Find Database Name In SQL Server
Let us discuss all those approaches individually.
Approach-1: Using sys.databases
To find database name in SQL server, we can execute the query below.
SELECT name AS DatabaseName
FROM sys.databases
ORDER BY name;
After executing the above query, I got the expected output as shown in the screenshot below.

If you wish to exclude the lists of system databases, you can execute the above query with the where condition as specified below.
SELECT name AS DatabaseName
FROM sys.databases
WHERE database_id > 4
ORDER BY name;
After executing the above query, I got the expected output below.

Check out How to insert a row in a view in SQL Server
Approach-2: Using SQL Server Management Studio (SSMS) Object Explorer
Follow the below simple steps
1. Connect to your SQL server instance in SSMS.
2. Once connected, expand the database folder under Object Explorer.

Check out View Line Numbers in SQL Server Management Studio
Approach-3: sp_databases stored procedure
We can also execute the sp_databases stored procedure for this purpose. This will provide the names of all the databases, including their size. We need to execute the below query.
EXEC sp_databases;
I got the expected output successfully after executing the above query.

Approach-4: Using the DB_NAME() Function
We can also use the DB_NAME() function to find out the name of my current SQL server database.
SELECT DB_NAME() AS CurrentDatabase;
After executing the above function, I got the expected output, as shown below.

Video Tutorial
Conclusion
Finding the name of the databases in SQL server is never difficult using the different approaches mentioned in this article. You can use sys.databases, sp_databases, DB_NAME(), and SQL server management Studio (SSMS) design approach for this purpose.
You may also like following the articles below.
- How to view table in SQL Server
- How to View SQL Server Error Logs
- How to Find Stored Procedure in SQL Server
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.