DB_NAME
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 FlowSELECT DB_NAME() AS current_database;
Open Microsoft Learn for full syntax, permissions, and details for your version.