Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Does someone who has worked extensibly SQL-wise with at least two top DB products (such as Oracle, SQL Server, Informix, Sybase, DB2, Teradata) know how different the DB vendor's SQL dialects are from each other. Since I come from an Oracle background, I am especially interested in

  • analytical functions
  • model clauses
  • hierachical queries (start with .. connect by comes to mind)
  • any other feature that is more than the usual (select x, y from a, b where...)

Probably, the question boils down to if and to what extent these features are regulated by an ansi standard.

Practically, I'd like to know if there are "rule of thumbs" that would indicate if (and how) I can take an SQL DML-statement that runs on one database and let it run on an other database.

share|improve this question

5 Answers 5

up vote 6 down vote accepted

ANSI is a private non-profit organization that creates voluntary standards. As such it doesn’t actually regulate anything. Often it is to a company’s benefit to follow recognized standards, which is why many database companies follow the ANSI standard for SQL. Of course as each company seeks to differentiate their products, they will develop additional functionality beyond the standards.

From w3schools:

Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.

However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.

Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!

The differences between the SQL dialects is too great in the more specialized areas you listed to simplify the problem down to a “rule of thumb”. In these situations you probably should convert the entire statement for each database. By doing this each statement can be optimized for each platform taking advantage of the special features each database can provide. Writing SQL to lowest common denominator (ANSI) may simplify migration, but at the cost of performance.

SQL Dialects Reference gives some useful comparisons of the SQL variants. For more information I recommend searching for the specific dialects you are switching between like this:

   differences between mysql and oracle sql

share|improve this answer
    
Only the first (1986) standardization was done by ANSI. I think some of the following were done by ISO/ANSI and the latest are now under the Joint Technical Committee of both ISO and IEC (wikipedia: SQL) –  ypercube Dec 28 '12 at 15:53

Some database vendors provide detailed information about their ANSI SQL standard compliance. For Teradata, they specifically list SQL standards for each element of the ANSI standard, and for each detailed item -- like for each function, data type, etc. I have not seen general assertions about Teradata compliance, but I did search two documents for "SQL:2", which would get any recent ANSI compliance. They are ANSI SQL:2011 compliant for everthing but triggers, stored procedures, and hex literals, which are compliant with SQL:2008.

The devil is in the details, and you must have them to determine how if a database is ANSI SQL compliant at any level. Also it's not enough to fit the old standard of SQL-92 (aka SQL2). If a vendor provides good support for a newer standard, doesn't that say a lot about database quality?

A good place for information to compare database is "SQL In a Nutshell", 2nd or 3rd edition, by Kline, Kline and Hunt, and published by O'Reilly. They have several tables that compare different database features to SQL:2003. Teradata is not in the list, but since they are at least SQL:2003 compliant, I can use the list to compare database features.

Looking at the lists in the O'Reilly book, I can find features in Oracle that do not support the SQL:2003 standard. Of course, I need to check to Oracle documentation to verify those facts, since that book is dated. Then the Oracle to SQL:2003 comparison will help me in my big conversion project from Oracle to Teradata.

share|improve this answer

Each vendor generally conforms to a minimum core of standard syntax. SQL-92 is generally the standard most conform to. They then add additional functionality on top of that. SQL3 adds procedural functionality to the syntax standard. Conformance to this standard is a lot lower. Vendors often will make claims to certain conformity. Conforming to the standard only means that they supply "at least" this functionality. They can supply any amount of functionality and therefore syntax beyond that standard. Each database vendor than also adds functionality that is specific to the way that they implement their database structure. This is how each database vendor attempts to provide an edge over their competition. Minor or no syntax difference are common for more universal functionality but since a lot of people make the decision about their database vendor based on the additional functionality that they provide or support this can be the key functionality that is vastly different or non existent between vendors.

share|improve this answer

Just tossing it out there for discussion, even tho it could've likely been a comment as well. This is why most people like using the various frameworks nowadays like EntityFramework and LINQ, where all the underlying abstraction of querying is relegated to the application layer, and the datalayer is just flat storage.

Note that this gives another benefit to the NoSQL crowd, as the database is just a storage medium.

share|improve this answer

At one time or another I've worked with all of the databases you mention. Unfortunately I have found that it doesn't take very long at all for the syntax to deviate in to their own flavours, for anything other than the simplest SELECT, INSERT, UPDATE and DELETE. When it gets to some of the categories you suggest it will quickly get vendor specific. I've always pretty much had to 'port' my SQL from one platform to another. Although going back a few years I was amazed at how different SQL Server and Teradata SQL was for even an UPDATE with a a few joins in it was.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.