How can I write a SQL query to get the database name ?

Tags:
Database name
SQL 2008
SQL Database
SQL Query
How can I write a SQL query to get the DB name ? Usually we use SELECT DB_NAME() AS DataBaseName, but at that time teh DB is in use. If we didn;t write use [dbname][/dbname], is there any way to get the DB name ?

Software/Hardware used:
SQL 2008

Answer Wiki

Thanks. We'll let you know when a new response is added.

Are you trying to get the instance name? That can be gotten by running

<pre>SELECT @@SERVERNAME</pre>

If you are trying to get the database name, you already have the code to get that.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Meandyou
    Not all RDBMSes have the ability to tell you what instance or location or whatever. So at install time, I make it a practice to always add a table containing any and all pieces of info anyone might want. Make the table available to everyone. table might include INSTANCE, LOCATION, LPAR, DATE INSTALLED, SOFTWARE VERSION, ... Caveat - just remember to update the info if you clone this instance
    5,220 pointsBadges:
    report
  • KulkarniMandar
    [...] KulkarniMandar asked his first question: How can I write a SQL query to get the database name? Mr. Denny and Meandyou helped him out. Welcome to the community, [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following