DB_ID (T-SQL)

Returns the database identification number.

Syntax

DB_ID(['database_name'])

Arguments
'database_name'
Is the database name used to return the corresponding database identification number. database_name is nvarchar. If database_name is omitted, the ID of the current database is returned.
Return Types

smallint

Examples

This example examines each database in sysdatabases using the database name to determine the database identification number.

USE master

SELECT name, DB_ID(name) AS DB_ID

FROM sysdatabases

ORDER BY dbid

  

Here is the result set:

name                           DB_ID 

------------------------------ ------

master                         1     

tempdb                         2     

model                          3     

msdb                           4     

pubs                           5     

  

(5 row(s) affected)

  

See Also

Metadata Functions

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.