Determine flavor of SQL being used - sql

I have a mysterious SQL database presented through a web interface. I tried to show tables; but was told that's not a valid command, so I'm trying to figure out what flavor of SQL this is.
Does anyone know a command that can help identify the flavor of SQL being used? Any pointers would be very helpful!

Not an answer but a comment that doesn't fit in the comments. You can start by trying the following commands and see if one succeeds:
Oracle: select * from V$VERSION;
DB2: select service_level from sysibmadm.env_inst_info;
PostgreSQL: select version();
SQL Server: select ##version;
MariaDB: select version();
MySQL: select version();
H2: SELECT H2VERSION() FROM DUAL
SQLite: select sqlite_version();
Firebird: select rdb$get_context('SYSTEM', 'ENGINE_VERSION') as version from rdb$database;
HyperSQL gives itself away by implementing the BOOLEAN and INTERVAL types.
In Derby you can select from the table sysibm.sysdummy1 (as well as in DB2).

Related

Oracle system information query - Database instance level

I am writing a performance/system monitoring tool to augment load testing for my team's product and I am trying to store database system information with the results bundle but do not know how to write the query to capture this in Oracle (I'm a developer not a DBA).
I have this all working the way I want for SQL Server, but I need to do the same for Oracle. Below is a query I found online for this is SQL Server:
SELECT CONVERT(varchar(128),SERVERPROPERTY('ComputerNamePhysicalNetBIOS')) AS 'computerNamePhysicalNetBIOS',
CONVERT(varchar(128),SERVERPROPERTY('MachineName')) AS 'machineName',
CONVERT(varchar(128),SERVERPROPERTY('Edition')) AS 'edition',
CONVERT(varchar(128),SERVERPROPERTY('ProductLevel')) AS 'productLevel',
CONVERT(varchar(128),SERVERPROPERTY('ProductVersion')) AS 'productVersion',
CONVERT(varchar(128),SERVERPROPERTY('BuildClrVersion')) AS 'buildClrVersion',
CONVERT(INT,SERVERPROPERTY('ProcessID')) AS 'processID',
CONVERT(INT,SERVERPROPERTY('EngineEdition')) AS 'engineEdition',
CONVERT(INT,SERVERPROPERTY('HadrManagerStatus')) AS 'hadrManagerStatus',
CONVERT(INT,SERVERPROPERTY('IsHadrEnabled')) AS 'hadrEnabled',
CONVERT(INT,SERVERPROPERTY('IsAdvancedAnalyticsInstalled')) AS 'advancedAnalyticsInstalled',
CONVERT(INT,SERVERPROPERTY('IsClustered')) AS 'clustered',
CONVERT(INT,SERVERPROPERTY('IsPolybaseInstalled')) AS 'polybaseInstalled',
CONVERT(INT,SERVERPROPERTY('IsXTPSupported')) AS 'xtpSupported',
CONVERT(INT,SERVERPROPERTY('LCID')) AS 'lcid',
CONVERT(varchar(128),SERVERPROPERTY('ResourceVersion')) AS 'resourceVersion',
CONVERT(varchar(128),SERVERPROPERTY('ServerName')) AS 'serverName',
CONVERT(varchar(128),APP_NAME() )AS 'appName',
CONVERT(INT,DB_ID()) AS 'dbId',
CONVERT(varchar(128),DB_NAME()) AS 'dbName'
I don't really expect a one-to-one column match between the above query and Oracle's version, but in general, how can I get very similar information from Oracle?
I don't really expect a one-to-one column match between the above
query and Oracle's version, but in general, how can I get very similar
information from Oracle?
Most of that stuff, if it exists at all in the Oracle database, will be accessible through V$ views in the Oracle database. To get you started, here are some that are going to be most relevant to answering your question:
select * from v$instance;
select * from v$version;
select * from v$sql_feature;
select * from v$license;
select * from v$option;
If you want to get a complete list of V$ views to look around better,
select * from dict where table_name like 'V$%';
Some of those things are specific to MSSQL and have no meaning in Oracle. But you can get many of them with sys_context() using the userenv namespace.
For instance, to get the database name:
select sys_context('userenv', 'DB_NAME') as db_name
from dual;

How does Reserved keyword * works in sql

How does rdbms tools execute * in select statements. reason of asking the question is its different usage in different rdbms tools.
Ex: oracle and db2 gives error in below statements, however works fine in mysql,mssql,sybase. Looks like an issue with sql parser.
select col_name,* from table_name
Or
select *,col_name from table_name
Oracle (and probably DB2 as well) accepts an unadorned * only when there are no other column references or expressions in the SELECT.
However, it is always allowed with a table alias. So you can write:
select col_name, t.*
from table_name t
Just one caution: the result set will have two columns with the same name, which can cause other problems.
Db2 11.1 supports unqualified *s. E.g.
db2 "create table table_name( col_name int )"
DB20000I The SQL command completed successfully.
db2 "select col_name,* from table_name"
COL_NAME COL_NAME
----------- -----------
0 record(s) selected.
https://en.wikipedia.org/wiki/SQL#Interoperability_and_standardization
SQL implementations are incompatible between vendors and do not necessarily completely follow standards.
See the Wikipedia link above for some of the "several reasons for this lack of portability between database systems"

Equivalent to minus in netezza

I want to compare data between two different db tables in netezza. In oracle we can do that by minus operator. How can the same operation be done in netezza.
SELECT CUSTOMER_SRC_ID,CUSTOMER_SRC_DESC FROM CIDB_SIT..CUSTOMER_SRC
MINUS
SELECT CUSTOMER_SRC_ID,CUSTOMER_SRC_DESC FROM EDW_SIT..CUSTOMER_SRC
Seems like it doesn't work in netezza. Can any one help me find the equivalent query in netezza?
The ANSI-SQL standard calls this operators except. Netezza implements it, as do PostgreSQL and MS SQL Server:
SELECT CUSTOMER_SRC_ID,CUSTOMER_SRC_DESC FROM CIDB_SIT..CUSTOMER_SRC
EXCEPT -- Here
SELECT CUSTOMER_SRC_ID,CUSTOMER_SRC_DESC FROM EDW_SIT..CUSTOMER_SRC
You could use the EXCEPT
or
--if customer_src_id is unique--
SELECT CUSTOMER_SRC_ID,CUSTOMER_SRC_DESC
FROM CIDB_SIT..CUSTOMER_SRC
WHERE CUSTOMER_SRC_ID NOT IN (SELECT CUSTOMER_SRC_ID FROM EDW_SIT..CUSTOMER_SRC);

query oracle database for availability

Is there a lightweight sql statement that I can against an oracle database to test if the database is up, available and able to exceute sql?
SELECT 1
FROM dual
is a common one. You could select any constant value from DUAL as well.
If you don't want to connect first, you could query through a link, for example, I have a set of links to an external system and I run SQL of the following form:
select * from global_name#myLink01.WORLD;
If you write the sql statement to describe dual table, then also you will get to know it whether db is up and running.
desc dual;

How to test the connection to a db2 database

I need to test the connection to a db2 database.
With oracle databases I'd execute a 'select * from dual' in order to do this.
But dual is specific for oracle. Is there a similar canonical test sql statement for db2?
SELECT 1 FROM SYSIBM.SYSDUMMY1
cheaper then
SELECT CURRENT SQLID FROM SYSIBM.SYSDUMMY1
I ended up using
SELECT CURRENT SQLID FROM SYSIBM.SYSDUMMY1
which seems to work nice.
LIST DB DIRECTORY
or
LIST TABLES