Returns the database name.
DB_NAME(database_id)
nvarchar(128)
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)