|
SQL Cheatsheet
KEY --- Curly braces group alternatives together, and alternatives are separated by pipes: {this | that | t'other} Clauses in brackets are optional: You [and john] can come. An asterisk indicates 0 or more instances: I like to eat[ and eat]*. A plus-sign indicates 1 or more instances: Run fast,[ go]+! A plus-sign also indicates addition: select (1 + 3) from dual; Elements are defined in terms of other elements. <number> : [0-9]+ means that a number is composed of one or more digits. <datatype>: {integer | char(<number>) | varchar2(<number>) | date} means that a <datatype> element is one of the four strings shown. <column-set>: <column> = <expression> means that a <column-set> element is composed of a <column>, followed by an equals sign and an <expression>. Readability of PL/SQL is much improved by highlighting certain keywords; this is why some word are in all caps. Permanent link building services --- INSERTS and UPDATES ------------------- <insert>: insert into <tablename> [<columns>] {values <values> | <select>} <select>: select [distinct] <columns> from <tables> [<where>] [group-by] <select-union>: <select> union <select> [<order-by>] <select-order>: <select> <order-by> <update> : update <tablename> set <column-set> [, <column-set>] [<where>] <column-set>: <column> = <expression> <update-from-query>: update <tablename> set <columns> = <select> [<where>] FUNDAMENTALS ------------ <name> : [a-zA-Z][a-zA-Z0-9_]* - that is, a string of alphanumeric chars and underscores starting with an alpha char. <number> : [0-9]+ <datatype>: {integer | char(<number>) | varchar2(<number>) | date} <ora-alias>: a temporary nickname for a table or column, for the purposes of condensing a query. LITERALS -------- <value> : {<number> | <string> | <number-expr> | <string-expr>} <values> : ( <value> [, <value>]* ) <number-expr>: {<number> | <column-name>} + [<number> | <column-name>]* <string-expr>: {<string> | <column-name>} || [<string> | <column-name>]* NAMES and DEFINITIONS --------------------- <column-name>: name of a column in a table in the current scope <columns> : ( <column-name> <ora-alias> [, <column-name> <ora-alias>]* ) <new-column> : <name> <column-def> <new-columns>: <new-column> [, <new-column>]* <column-def> : <datatype> [default <value>] [<constraint>]* <table-name> : name of a table in the current scope <tables> : <table-name> <ora-alias> [, <table-name> <ora-alias>]* <constraint> : {not null | primary key | references <table-name>}
|