DB_NAME()

The DB_NAME function returns the name of a specified database.

Signature

DB_NAME ( [ database_id ] )

Parameters

  • database_id — The identification number (ID) of the database whose name `DB_NAME` returns. If the call to `DB_NAME` omits *database_id*, or the *database_id* is `0`, `DB_NAME` returns the name of the current database.

Examples

SELECT DB_NAME() AS [Current Database];
navidog_docs
SELECT DB_NAME(database_id) AS [Database],
       database_id
FROM sys.databases;
master|1
tempdb|2
model|3
msdb|4
ShopDB|5
Northwind|6
navidog_docs|7

Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.

Available on

  • SQL Server 2017 and later
  • Azure SQL Database
  • Azure SQL Managed Instance
  • Azure Synapse Analytics
  • Analytics Platform System (PDW)
  • Microsoft Fabric warehouse
  • Fabric SQL database

Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.