Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

DB_NAME (Transact-SQL)

Returns the database name.

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.

Topic link icon Transact-SQL Syntax Conventions

DB_NAME ( [ database_id ] )


Is the identification number (ID) of the database to be returned. database_id is int, with no default. If no ID is specified, the current database name is returned.


A. Returning the current database name

The following example returns the name of the current database.

SELECT DB_NAME() AS [Current Database];

B. Returning the database name of a specified database ID

The following example returns the database name for database ID 3.

USE master;
SELECT DB_NAME(3)AS [Database Name];

Community Additions

© 2015 Microsoft