Reputation: 82341
I need to get the name of the database I am currently running against (to use in a URL column).
I know I can get the server name by using @@ServerName. But there is no @@DatabaseName.
How can I get the database that is currently being run against?
Upvotes: 3
Views: 116
Reputation: 504
You can use this function to get the database name which you are currently using
select DB_NAME()
Upvotes: 0
Reputation: 2398
You can use DB_NAME() to get the database name.
SELECT DB_NAME() AS DataBaseName
Upvotes: 1
Reputation: 171411
Try using this:
select DB_Name()
An example where the database changes:
use master
select DB_Name()
use model
select DB_Name()
Upvotes: 5