DB_NAME (TSQL Function)

Returns the name of the database with the specified ID.

Syntax

DB_NAME ( [database_id] )

Arguments

‘database_id’
optional argument, of type bigint. If omitted, the name of the current database is returned.

Return Types

Returns varchar.

Remarks

Returns NULL if the database doesn’t exist.

Examples

PRINT DB_NAME();
PRINT DB_NAME(100);
PRINT DB_NAME(-123);

The result is:

sales
trashdb
<NULL>
RSQL, a simple alternative to Microsoft SQL Server