DB_NAME (Transact-SQL)
SQL Server 2005
Returns the database name.
Transact-SQL Syntax Conventions
A. Returning the current database name
The following example returns the name of the current database.
SELECT DB_NAME() AS [Current Database]; GO
B. Returning the database name of a specified database ID
The following example returns the database name for database ID 3.
USE master; GO SELECT DB_NAME(3)AS [Database Name]; GO
Reference
DB_ID (Transact-SQL)Metadata Functions (Transact-SQL)
sys.databases (Transact-SQL)