DB_NAME (T-SQL)

Returns the database name.

Syntax

DB_NAME(database_id)

Arguments
database_id
Is the ID of the database to be returned. database_id is smallint, with no default. If no ID is specified, the name of the current database 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


(c) 1988-98 Microsoft Corporation. All Rights Reserved.