T-SQL Tutorial

How to get SQL Server database id


To get SQL Server database id uses function DB_ID().

Syntax

DB_ID ( )

DB_ID ( 'database name' )



Example

SELECT DB_ID();

SELECT DB_ID(N'tempdb');

See also: DB_ID