Export (0) Print
Expand All
ABS
ALL
AND
ANY
AVG
bit
COS
COT
DAY
EXP
GO
IN
LEN
LOG
MAX
MIN
NOT
OR
PI
SET
SIN
STR
SUM
TAN
USE
VAR
Expand Minimize

DB_ID

SQL Server 2000

Returns the database identification (ID) number.

Syntax

DB_ID ( [ 'database_name' ] )

Arguments

'database_name'

Is the database name used to return the corresponding database ID. database_name is nvarchar. If database_name is omitted, the current database ID is returned.

Return Types

smallint

Examples

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

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft