Transact-SQL Reference
DB_NAME
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)