Skip to content

Instantly share code, notes, and snippets.

@thibaultlaurens
Last active May 1, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thibaultlaurens/4586266 to your computer and use it in GitHub Desktop.
Save thibaultlaurens/4586266 to your computer and use it in GitHub Desktop.
Oxford Brookes MSc - SQL cheatsheet
* CREATE TABLE table_name (attribute1 type, ... , attributeN type)
* Types: char(n), varchar(n), int, smallint, real, DATE, TIME, DATETIME
* INSERT INTO table_name VALUES ( ... )
* DROP TABLE table_name
* ALTER TABLE table_name ADD COLUMN new_column type
ALTER TABLE table_name DROP COLUMN column type
* DELETE FROM table_name WHERE some_column = some_value
* id integer primary key autoincrement
foreign key (primary key) references pk_table_name
* SELECT aatribute_name_list
FROM table_name
WHERE condition
* LIKE letters, _, %
* Duplicates: DISTINCT, UNION, INTERSECTION, EXCEPT
* ORDER BY and GROUP BY
* Aggregates: min, max, count, sum, avg, distinct
* HAVING, NATURAL JOIN, JOIN ON
* SUMMARY:
SELECT [DISTINCT] target_list
FROM table_name [, table_name] *
[WHERE predicate]
[GROUP BY attribute_name] [, attribute_name] *
[HAVING function_list]
[ORDER BY attribute_name [DESC] [, attribute_name [DESC]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment