DB_ID (TSQL Function)
Returns the ID of the database.
Syntax
DB_ID ( ['database_name'] )
Arguments
- ‘database_name’
- optional argument, of type
varchar
. If omitted, the ID of the current database is returned.
Return Types
Returns bigint
.
Remarks
Returns NULL if the database doesn’t exist.
Examples
PRINT DB_ID();
PRINT DB_ID('trashdb');
PRINT DB_ID('non_existent_database');
The result is:
106
100
<NULL>