Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2005
 DB_NAME (Transact-SQL)

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SQL Server 2005 Books Online (November 2008)
DB_NAME (Transact-SQL)

Returns the database name.

Topic link icon Transact-SQL Syntax Conventions

DB_NAME ( [ database_id ] )
database_id

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

nvarchar(128)

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker