Question

  Asked: Jul 2 2008   5:49 PM GMT
  Asked by: SQL Server Ask the Experts


Looking for a database name query in SQL


SQL, Query, Database, SQL Query, SQL Server

Is there a query in SQL that could return me the name of a database, or whether it is connected to SQL Server or Oracle?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



If you run the following query on SQL Server it will tell you the name of the database you are in.

SELECT db_name()


As fr as I know there is no code that can be run on both SQL Server and Oracle to find out what platform you are connected to.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development, Database and SQL Server.

Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Mrdenny  |   Jul 2 2008  8:00PM GMT

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 

Ritchie1  |   Jul 4 2008  8:14AM GMT

To see if Oracle or SQL Server are running check each’s version - one will return an answer the other will cause an error. Handle the error - and you know if it is Oracle or SQL Server.

To determine which version of Microsoft SQL Server:
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)

To determine which version of Oracle:
select * from v$version
where banner like ‘Oracle%’;
It should return something like this:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production