0

I want to select the name of the Db on which I am running a query and PRINT it.

How can I achieve this in T-SQL?

something like:

DECLARE @ActualDbName VARCHAR(200)
SET @ActualDbName  = -- SELECT ...
PRINT @ActualDbName 
steoleary
  • 8,968
  • 2
  • 33
  • 47
pencilCake
  • 51,323
  • 85
  • 226
  • 363
  • 1
    This may be what you are looking for. [Get Database Name][1] [1]: http://stackoverflow.com/questions/6774533/how-to-get-database-name-of-sqlserver – dthartman Jan 23 '14 at 15:00

2 Answers2

0

Use the function DB_NAME().

So you would replace your -- SELECT -- with something like:

SELECT DB_NAME() AS [Current Database];

Specified here: http://technet.microsoft.com/en-us/library/ms189753.aspx

Simon Brahan
  • 2,016
  • 1
  • 14
  • 22
0

Try this...

SELECT DB_NAME() AS DataBaseName

Courtesy : Source

M.K
  • 218
  • 3
  • 10