How can I write a SQL query to get the database name ?
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
ASKED: June 29, 2010  11:35 AM
UPDATED: June 30, 2010  3:43 PM

Answer Wiki:
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.
Last Wiki Answer Submitted:  June 29, 2010  7:38 pm  by  Denny Cherry   64,520 pts.
All Answer Wiki Contributors:  Denny Cherry   64,520 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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,205 pts.