Is there any standard sql command that can show you the current RDBMS and version?
The reason for this question is that I am using a CMS remotely that use a SQL database, but I don't know which RDBMS is being used, so I thought maybe there is standard SQL command to print it, something similar to SQL server's ##version
This is not a direct answer to the question, but since there is no standard sql query or function to show the RDBMS, I will post the queries/functions/vars used to identify it.
-- SQL SERVER
SELECT ##version;
-- Postgres, mysql, mariadb
SELECT version();
-- Oracle
SELECT * FROM v$version;
-- sqlite
select sqlite_version();
Please pay attention that Mysql and Sqlite will show only the version and will not include engine name in contrast to other RDBMS.
Related
I made a relational model in Oracle SQL Developer and I want to make tables in MySQL Workbench. I generated the DDL script in SQL Developer and copied it in MySQL Workbench. I found out that the copied queries are not in correct syntax. I tried different options in SQL Developer to generate script and none of them were in MySQL syntax.
Is there a way to generate DDL script from a model, which is made in SQL Developer, for MySQL?
There is no straight query generation for MySQL in oracle SQL developer. You should use such a sites for your purpose to convert them into MySQL syntax or use tools for automatic converting.
I am looking for a small and simple query that works on Oracle and SQL Server.
It is used as a test query to check the connection.
For SQL Server we used SELECT 1, but in Oracle it would have to be SELECT 1 FROM DUAL.
What we plan to use now is SELECT COUNT(*) FROM (sometable) but any ideas for an even simpler query are appreciated.
One simple option is to add a view to SQL Server called DUAL that just returns 1, that way you can have a simple query that works the same in both environments:
SELECT 1 FROM DUAL
If returning data from relations isn't important then:
SELECT 'Hello world';
will rely on a connection as much as anything else. Your RDBMS should return 'Hello world'. Tested on SQL server and PostgreSQL (don't have access to Oracle).
As long as you write query in ANSI standard. It can be executed in all the RDMS.
May be you can try this query....
select ColumnName from TableName where 1=2
BTW, the DBProvider shld have come property to state of DB connectivity... which DB provider does ur application uses?
Does it need to be a query? You could create a simple stored procedure with the same name in both databases, that just returns a constant, and execute it from the application server.
I never seen this, but is it possible to have one SQL call join data from Oracle and SQl Server?
Yes, Oracle and SQL Server both have functionality that allows to connect to other databases, including different vendors. In Oracle terminology, it's a database link instance while on SQL Server it's called a Linked Server instance.
The syntax to reference the instance is different between Oracle and SQL Server though. IE:
Oracle:
SELECT t.*
FROM table_name#database_link_instance t
SQL Server:
SELECT t.*
FROM linked_server_instance_name.database_name.schema_name.table_name t
does MySQL support the linked server concept?
No, the closest MySQL has is the FEDERATED engine, which is only for connecting to remote MySQL instances.
PostgreSQL?
PostgreSQL has dblink. Last time I looked at dblink (pre-v9 release), it only could connect to other PostgreSQL instances.
Yes- both Oracle and SQL Server support the linked server concept. That allows you to reference the other server using a 4 part name. For example:
select *
from LocalDb.Schema.Table
cross join
OracleLinkedServer.RemoteDb.RemoteSchema.RemoteTable
Drupal uses db_query_range() for the reason that not all databases support LIMIT,
can you name a few?
DB2, MSSQL, Oracle, and Informix all do not support LIMIT. As a matter of fact, it's not in the SQL standard. (The standard one is "FETCH FIRST" indeed)
Here is a good source for SQL comparisons: http://troels.arvin.dk/db/rdbms/#select-limit
Microsoft SQL Server does not support LIMIT. It supports the TOP statement which can be used to accomplish similar things. The primary limitation with TOP is the inability to specify an offset.
ms sql, oracle.
and actually LIMIT doesn't exists in ANSI SQL '92 which all modern databases should follow. so currently it's just an unnecessary extension/syntactic sugar/specific sql dialect
DB2, Oracle, and MS SQL Server do not support the LIMIT clause.
Google for <database name> LIMIT, and you'll get to know the equivalent supported clause for that database, or whether LIMIT itself is supported.
On the flip side, ANSI-92 SQL provides the ROW_NUMBER() window function for achieving this, which is supported on many databases. See SELECT (SQL) on Wikipedia.
The developer environment db server is SqlServer 2005 (developer edition)
Is there any way to make sure my SQL Queries will run in SqlServer 2000?
This database is set to Compatibility level "SQL Server 2000 (80)" but some queries that run without problems in the development system can not run in the Test Server (SqlServer).
(The problems seems to be in subqueries)
Compatibility levels are designed to work the opposite way - to allow an older version of T-SQL code to work without modifications on a newer version of SQL Server. The changes typically involve T-SQL syntax and reserved words, and it's possible to use SQL Server 2005 features such as INCLUDED columns in indexes on a database in Compatibility Level 80. However, you can't use 2005 T-SQL features such as CROSS APPLY.
Your best option is to develop/test all your code against a SQL Server 2000 instance. Note that you can use 2005's Management Studio to connect to the SQL Server 2000 instance, so you don't have to go backwards with regards to tools.
Problem solved:
In correlated subqueries you have to (in SQL2000) explicitly define the external field.
SQL2005:
SELECT * FROM Loans WHERE EXISTS (SELECT * FROM Collaterals WHERE COLLATERAL_LOAN=LOAN_NUMBER)
SQL2000:
SELECT * FROM Loans WHERE EXISTS (SELECT * FROM Collaterals WHERE COLLATERAL_LOAN=Loans.LOAN_NUMBER)
You should always explicitly define all fields, otherwise you will not get an error when you make a mistake and write
SELECT * FROM Loans WHERE EXISTS (SELECT * FROM Collaterals WHERE LOAN_NUMBER=Loans.LOAN_NUMBER)
If Collaterals-table doesn't have column LOAN_NUMBER, the Loans-table is used instead.