Misc

Case sensitivity

  • SQL is case insensitive

String literals

  • Use single quotes

Conditionals

  • case, nullif, coalesce, ...

SQL tuning

  • Finding the fastest SQL statement for a given operation
  • The most reliable approach is to try a number of SQL statements and compare the execution time
  • It helps to have a general knowledge of how SQL statements work, how the DB is indexed, and how the DB engine is optimized
  • There are no general rules of thumb that work in all cases

Sub-areas of SQL

Data Definition Language (DDL)

  • Affects: tables, schema, catalogs, databases
  • Commands: create, alter, drop

DML (Data Manipulation Language)

  • Affects: records
  • Commands: select, insert, update, delete

Data Control Language (DCL)

  • Affects: privileges, transactions
  • Commands: grant, revoke, commit, rollback

Misc

  • Describe (shorthand for "show columns"): {describe | desc} tbl_name [col_name | wild]
  • Show columns: show [full] columns from tbl_name [from db_name] [like 'pattern']
  • Stored procedures
  • Triggers