Writing database implementation independant code
Table of contents:
Use the API of the database handlers
Common mistakes in SQL
Quoting literal string values
Use single quotes ( ' ) to quote literal string values, not double quotes ( " ). Certain database servers interpret a double quote as an identifier quote character.
Example
Wrong:
Right:
MySQL
By default MySQL allows double quotes to quote literal string values. However, you can turn on the ANSI_QUOTES SQL mode to make sure MySQL treats a double quote as an identifier quote character.
Aliases for columns and tables
Columns should be aliased with the AS keyword (example 1), tables should NOT be aliased with the AS keyword (example 2).
Example 1
Wrong:
Right:
Example 2
Wrong:
Right: