4 out of 4 rated this helpful - Rate this topic

DB_NAME

SQL Server 2000

Returns the database name.

Syntax

DB_NAME ( database_id )

Arguments

database_id

Is the identification number (ID) of the database to be returned. database_id is smallint, with no default. If no ID is specified, the current database name is returned.

Return Types

nvarchar(128)

Examples

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

USE master
SELECT dbid, DB_NAME(dbid) AS DB_NAME
FROM sysdatabases
ORDER BY dbid
GO

Here is the result set:

dbid   DB_NAME                        
------ ------------------------------ 
1      master                         
2      tempdb                         
3      model                          
4      msdb                           
5      pubs                           

(5 row(s) affected)

See Also

Metadata Functions

Did you find this helpful?
(1500 characters remaining)