Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

database query Expand / Collapse
Author
Message
Posted Tuesday, March 31, 2009 3:52 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, April 26, 2014 6:12 AM
Points: 88, Visits: 468
hello,

i'am trying to create a query which gives me back the database name and the instancename of that particular database and put all of this in a table. can someone help me with this issue.

kind regard,
bryan
Post #686821
Posted Tuesday, March 31, 2009 4:08 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 1:28 AM
Points: 2,105, Visits: 5,393
It isn’t very clear what you want to do. Do you want to get a list of databases in the instance? If this is what you want you can use this query:
select @@servername, name from master.sys.databases

If you want something else, pleas specify.

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #686827
Posted Tuesday, March 31, 2009 4:59 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 11:13 AM
Points: 15,527, Visits: 27,909
As the last post showed, @@ServerName gets you the name of the server, DB_NAME() gets you the current database. If you pass it a database ID, it will get any other database name.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #686862
Posted Tuesday, March 31, 2009 5:45 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, April 26, 2014 6:12 AM
Points: 88, Visits: 468
Hi Adi,

thanks for your reply, just what i was looking for. thanks again.

bryan
Post #686902
Posted Tuesday, March 31, 2009 5:46 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, April 26, 2014 6:12 AM
Points: 88, Visits: 468
Hi Grant,

thanks for the remark. just like Adi suggested worked for me.

bryan
Post #686905
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse