Is there a variable like @@ ServerName, but for the database name?

I need to get the name of the database I'm currently running in (for use in the URL column).

I know that I can get the server name using @@ ServerName. But no @@ DatabaseName.

How can I get the database that is currently running?

+3
source share
3 answers

Try using this:

select DB_Name()

Example database change:

use master
select DB_Name()
use model
select DB_Name()
+5
source

You can use DB_NAME () to get the database name.

SELECT DB_NAME() AS DataBaseName
+1
source

You can use this function to get the name of the database you are currently using.

select DB_NAME ()

0
source

All Articles