In this SQL Server tutorial, you will learn to find database name in SQL Server Management Studio.
You will understand how to find the name of the database through Object Explorer in SSMS. After that, you will learn through examples how to find the name of a database using a query in SSMS.
Find Database Name in SQL Server Management Studio
Finding the name of the database is the fundament task of every database developer and administrator, or whoever is working with the database. So here you will learn how to find the name of a database using SSMS.
Open the SSMS and connect to the SQL Server instance by clicking on the connect button as shown below.

Now go to the Object Explorer area on the left side of the screen and then expand the Databases node. This node contains all the databases on the SQL Server instance.

After expanding the Databases node, you can see all the databases on your SQL Server such as System Databases, Database Snapshots, and user-created databases as shown in the above picture.
Now you can search through the list to find the name of the database you are interested in.
Find Database Name in SQL Server Management Studio: using Query
You can also execute the query in SQL Server Management Studio to find the name of the database on the SQL Server instance. To run the query, open the Query Editor by pressing the CTRL + N on your keyboard.
Within the query editor, write the below query to find the name of the database based on the provided ID of the database.
SELECT name FROM sys.databases
WHERE database_id = 5;
The above query finds the name of the database from the system catalog (sys.databases) view in SQL Server. The system catalog in SQL Server stores information about all the databases on the SQL Server instance.

When you execute the above query it returns the Orders database whose ID is 5 on the SQL Server instance.
Instead of 5, you can provide the ID of any database whose name you want to find, and the query will return the name of that database.
Now if you are connected to any database and you are not sure about the name of that database, you can execute the below query to find the name of the database to which you are currently connected.
SELECT DB_NAME();

The above query returns the model database to which the user is connected currently. This is how to find database name in SQL Server Management Studio using the DB_NAME() function.
The function DB_NAME() which is used with the SELECT statement finds and returns the name of the current database.
You can also provide the ID of the database to the DB_NAME() function to find the name of a specific database.
Suppose again you want to find the name of the database with an ID equal to 5 using the DB_NAME() function, use the below query.
SELECT DB_NAME(5);

When you provide the ID which is equal to 5 to the function DB_NAME(), it returns the name of the database which is Orders that you can see in the above output.
This is how to find database name in SQL Server Management Studio using the DB_NAME() function with the database ID.
Conclusion
In this SQL Server tutorial, you learned how to find the name of a database in SQL Server Management Studio. After that, you learned how to find the name of the database using the query. You have used the system catalog view and DB_NAME() function to find the name of the database in SQL Server.
You may also like:
- How to Find Database Name in SQL Server Using Query?
- How to Get Connection String in SQL Server Management Studio?
- How to Get Server Name in SQL Server using Query?
After working for more than 15 years in the Software field, especially in Microsoft technologies, I have decided to share my expert knowledge of SQL Server. Check out all the SQL Server and related database tutorials I have shared here. Most of the readers are from countries like the United States of America, the United Kingdom, New Zealand, Australia, Canada, etc. I am also a Microsoft MVP. Check out more here.