Reputation: 49
I am working on Microsoft SQL server management studio. I have 15 different databases under the Databases folder. All the databases have similar structure and tables. I wrote a query that will work on any database. However i want to know how can I find out the name of the currently used database, I want this to show in my result set. Please advise?
Upvotes: 2
Views: 112
Reputation: 49
DB_NAME() method can get you the name of the current database. Answered by StuartLC.
Upvotes: 0
Reputation: 453756
Sounds like you need the DB_NAME()
function.
It accepts an optional database_id
parameter. If omitted it returns the name of the current database.
Upvotes: 3