Looking for a database name query in SQL
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?

Software/Hardware used:
ASKED: July 2, 2008  5:49 PM
UPDATED: July 4, 2008  8:14 AM

Answer Wiki:
If you run the following query on SQL Server it will tell you the name of the database you are in. <pre>SELECT db_name()</pre> 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.
Last Wiki Answer Submitted:  July 2, 2008  7:59 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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 64,520 pts.

 

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

 210 pts.