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
7 out of 7 rated this helpful - Rate this topic

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

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.