DB_ID() Metadata Function TSQL Tutorial

The db_id returns a number that is id of the database.

DB_ID() Syntax:

DB_ID()
DB_ID ( 'database_name' )

DB_ID() Example:

SELECT DB_ID() AS Database_1,
DB_ID(N'master') AS Database_2;

Database_1Database_2
11

See also: T-SQL Functions -> APP_NAME | DB_NAME | OBJECT_DEFINITION | OBJECT_ID