SQL Flow Field Guide

DB_NAME

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

catalog lookup

What changes

Input
catalog metadata (object, column, index, file, database properties)
Output or change
id, name or property value
Return type
nvarchar(128)

Syntax at a glance

DB_NAME ( [ database_id ] )

Work example

Label a diagnostic result with the current database name.

Treat the result as context, not as a trusted authorization decision.

Check your work DB_NAME without an argument returns the current database name and can return null for an inaccessible database id.

Practice SQL

Open in SQL Flow
SELECT DB_NAME() AS current_database;

Open Microsoft Learn for full syntax, permissions, and details for your version.