Skip to content

Commit 779b56d

Browse files
authored
Merge PR #272: More documentation for SQL syntax
2 parents 97c9c49 + e2efa55 commit 779b56d

File tree

7 files changed

+537
-14
lines changed

7 files changed

+537
-14
lines changed

sql/create-table.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# CREATE TABLE statement
2+
3+
[SQL standard][] specifies the following CREATE TABLE syntax:
4+
5+
CREATE [{GLOBAL | LOCAL} TEMPORARY] TABLE
6+
7+
Dialects have considerable variation:
8+
9+
[BigQuery][]:
10+
11+
CREATE [OR REPLACE] [TEMP | TEMPORARY] TABLE [IF NOT EXISTS]
12+
13+
[DB2][]:
14+
15+
CREATE [GLOBAL TEMPORARY] TABLE
16+
17+
[Hive][]:
18+
19+
CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]
20+
21+
[MariaDB][]:
22+
23+
CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]
24+
25+
[MySQL][]:
26+
27+
CREATE [TEMPORARY] TABLE [IF NOT EXISTS]
28+
29+
[N1QL][]:
30+
31+
_No support for CREATE TABLE._
32+
33+
[PL/SQL][]:
34+
35+
CREATE [table_type] TABLE
36+
37+
table_type:
38+
{GLOBAL | PRIVATE} TEMPORARY
39+
| SHARDED
40+
| DUPLICATED
41+
| [IMMUTABLE] BLOCKCHAIN
42+
| IMMUTABLE
43+
44+
[PostgreSQL][]:
45+
46+
CREATE [[GLOBAL | LOCAL] {TEMPORARY | TEMP} | UNLOGGED] TABLE [IF NOT EXISTS]
47+
48+
[Redshift][]:
49+
50+
CREATE [[LOCAL] {TEMPORARY | TEMP}] TABLE [IF NOT EXISTS]
51+
52+
[Spark][]:
53+
54+
CREATE [EXTERNAL] TABLE [IF NOT EXISTS]
55+
56+
[SQLite][]:
57+
58+
CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]
59+
60+
[Transact-SQL][]:
61+
62+
CREATE TABLE
63+
64+
[sql standard]: https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_11_3_table_definition
65+
[bigquery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_statement
66+
[db2]: https://www.ibm.com/docs/en/db2/9.7?topic=statements-create-table
67+
[hive]: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableCreate/Drop/TruncateTable
68+
[mariadb]: https://mariadb.com/kb/en/create-table/
69+
[mysql]: https://dev.mysql.com/doc/refman/8.0/en/create-table.html
70+
[n1ql]: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/createscope.html
71+
[pl/sql]: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-TABLE.html
72+
[postgresql]: https://www.postgresql.org/docs/current/sql-createtable.html
73+
[redshift]: https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
74+
[spark]: https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table.html
75+
[sqlite]: https://www.sqlite.org/lang_createtable.html
76+
[transact-sql]: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver15

sql/create-view.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# CREATE VIEW statement
2+
3+
[SQL standard][] specifies the following CREATE VIEW syntax:
4+
5+
CREATE [RECURSIVE] VIEW
6+
7+
Dialects have considerable variation:
8+
9+
[BigQuery][]:
10+
11+
CREATE [OR REPLACE] VIEW [IF NOT EXISTS]
12+
13+
[DB2][]:
14+
15+
CREATE [OR REPLACE] VIEW
16+
17+
[Hive][]:
18+
19+
CREATE VIEW [IF NOT EXISTS]
20+
21+
[MariaDB][]:
22+
23+
CREATE
24+
[OR REPLACE]
25+
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
26+
[DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }]
27+
[SQL SECURITY { DEFINER | INVOKER }]
28+
VIEW [IF NOT EXISTS]
29+
30+
[MySQL][]:
31+
32+
CREATE
33+
[OR REPLACE]
34+
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
35+
[DEFINER = user]
36+
[SQL SECURITY { DEFINER | INVOKER }]
37+
VIEW
38+
39+
[N1QL][]:
40+
41+
_No support for CREATE VIEW._
42+
43+
[PL/SQL][]:
44+
45+
CREATE [OR REPLACE] [[NO] FORCE] [EDITIONING | EDITIONABLE [EDITIONING] | NONEDITIONABLE] VIEW
46+
47+
[PostgreSQL][]:
48+
49+
CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW
50+
51+
[Redshift][]:
52+
53+
CREATE [OR REPLACE] VIEW
54+
55+
[Spark][]:
56+
57+
CREATE [OR REPLACE] [[GLOBAL] TEMPORARY] VIEW [IF NOT EXISTS]
58+
59+
[SQLite][]:
60+
61+
CREATE [TEMPORARY | TEMP] VIEW [IF NOT EXISTS]
62+
63+
[Transact-SQL][]:
64+
65+
CREATE [OR ALTER] VIEW
66+
67+
[sql standard]: https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_11_22_view_definition
68+
[bigquery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_view_statement
69+
[db2]: https://www.ibm.com/docs/en/db2/9.7?topic=statements-create-view
70+
[hive]: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/AlterView
71+
[mariadb]: https://mariadb.com/kb/en/create-view/
72+
[mysql]: https://dev.mysql.com/doc/refman/8.0/en/create-view.html
73+
[n1ql]: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/createscope.html
74+
[pl/sql]: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-VIEW.html
75+
[postgresql]: https://www.postgresql.org/docs/current/sql-createview.html
76+
[redshift]: https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_VIEW.html
77+
[spark]: https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-view.html
78+
[sqlite]: https://www.sqlite.org/lang_createview.html
79+
[transact-sql]: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-ver15

sql/delete.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# DELETE statement
2+
3+
[SQL standard][] specifies the following DELETE syntax:
4+
5+
DELETE FROM { table_name | ONLY "(" table_name ")" } [[AS] alias]
6+
[WHERE condition | WHERE CURRENT OF cursor_name]
7+
8+
This base syntax is pretty well supported (except in Spark):
9+
10+
[BigQuery][]:
11+
12+
DELETE [FROM] table_name [alias]
13+
WHERE condition
14+
15+
[DB2][]:
16+
17+
DELETE FROM { table_name | ONLY "(" table_name ")" | "(" fullselect ")" }
18+
[[AS] correlation_clause]
19+
[INCLUDE include_columns]
20+
[assignment_clause]
21+
[WHERE condition | WHERE CURRENT OF cursor_name]
22+
[WITH {RR | RS | CS | UR}]
23+
24+
[Hive][]:
25+
26+
DELETE FROM table_name
27+
[WHERE condition]
28+
29+
[MariaDB][]:
30+
31+
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM table_name
32+
[PARTITION "(" partition_list ")"]
33+
[FOR PORTION OF period FROM expr1 TO expr2]
34+
[FROM from_clause]
35+
[USING using_clause]
36+
[WHERE condition]
37+
[ORDER BY ...]
38+
[LIMIT row_count]
39+
[RETURNING returning_clause]
40+
41+
[MySQL][]:
42+
43+
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM table_name [[AS] alias]
44+
[PARTITION "(" partition_list ")"]
45+
[WHERE condition]
46+
[ORDER BY ...]
47+
[LIMIT row_count]
48+
49+
[N1QL][]:
50+
51+
DELETE FROM table_name
52+
[USE [PRIMARY] KEYS expr]
53+
[WHERE condition]
54+
[LIMIT expr]
55+
[RETURNING returning_clause]
56+
57+
[PL/SQL][]:
58+
59+
DELETE [hint] FROM { table_name | ONLY "(" table_name ")" } [alias]
60+
[WHERE condition]
61+
[[RETURN | RETURNING] returning_clause]
62+
[LOG ERRORS error_logging_clause]
63+
64+
[PostgreSQL][]:
65+
66+
[WITH [RECURSIVE] with_clause]
67+
DELETE FROM [ONLY] table_name [ * ] [[AS] alias]
68+
[USING from_items]
69+
[WHERE condition | WHERE CURRENT OF cursor_name]
70+
[RETURNING returning_clause]
71+
72+
[Redshift][]:
73+
74+
[WITH [RECURSIVE] with_clause]
75+
DELETE [FROM] table_name
76+
[USING from_items]
77+
[WHERE condition]
78+
79+
[Spark][]:
80+
81+
_No support for DELETE_
82+
83+
[SQLite][]:
84+
85+
[WITH [RECURSIVE] with_clause]
86+
DELETE FROM table_name
87+
[FROM from_clause]
88+
[WHERE condition]
89+
[RETURNING returning_clause]
90+
91+
[Transact-SQL][]:
92+
93+
[WITH with_clause]
94+
DELETE [TOP ( expression ) [PERCENT]] FROM table_name
95+
[FROM from_clause]
96+
[WHERE condition | WHERE CURRENT OF [GLOBAL] cursor_name]
97+
[OPTION query_hints]
98+
99+
[sql standard]: https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_14_8_delete_statement_searched
100+
[bigquery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#delete_statement
101+
[db2]: https://www.ibm.com/docs/en/db2/9.7?topic=statements-delete
102+
[hive]: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Delete
103+
[mariadb]: https://mariadb.com/kb/en/delete/
104+
[mysql]: https://dev.mysql.com/doc/refman/8.0/en/delete.html
105+
[n1ql]: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/delete.html
106+
[pl/sql]: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/DELETE.html
107+
[postgresql]: https://www.postgresql.org/docs/current/sql-delete.html
108+
[redshift]: https://docs.aws.amazon.com/redshift/latest/dg/r_DELETE.html
109+
[spark]: https://spark.apache.org/docs/latest/sql-ref-syntax.html#dml-statements
110+
[sqlite]: https://www.sqlite.org/lang_delete.html
111+
[transact-sql]: https://docs.microsoft.com/en-us/sql/t-sql/statements/delete-transact-sql?view=sql-server-ver16

sql/insert.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# INSERT statement
2+
3+
[SQL standard][] specifies the following CREATE TABLE syntax:
4+
5+
INSERT INTO table_name
6+
7+
All dialects (except Hive) suppurt this syntax, plus a bunch of extra stuff:
8+
9+
[BigQuery][]:
10+
11+
INSERT INTO table_name
12+
13+
[DB2][]:
14+
15+
INSERT INTO table_name
16+
17+
[Hive][]:
18+
19+
INSERT INTO TABLE table_name
20+
21+
[MariaDB][]:
22+
23+
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] table_name
24+
25+
REPLACE [LOW_PRIORITY | DELAYED] [INTO] table_name
26+
27+
[MySQL][]:
28+
29+
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] table_name
30+
31+
REPLACE [LOW_PRIORITY | DELAYED] [INTO] table_name
32+
33+
[N1QL][]:
34+
35+
INSERT INTO table_name
36+
37+
[PL/SQL][]:
38+
39+
INSERT [hint] [ALL] INTO
40+
41+
[PostgreSQL][]:
42+
43+
INSERT INTO table_name
44+
45+
[Redshift][]:
46+
47+
INSERT INTO table_name
48+
49+
[Spark][]:
50+
51+
INSERT [INTO | OVERWRITE] [TABLE] table_name
52+
53+
[SQLite][]:
54+
55+
INSERT [OR {ABORT | FAIL | IGNORE | REPLACE | ROLLBACK}] INTO table_name
56+
57+
REPLACE INTO table_name
58+
59+
[Transact-SQL][]:
60+
61+
INSERT [TOP ( expression ) [PERCENT]] [INTO] table_name
62+
63+
[sql standard]: https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#insert-statement
64+
[bigquery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#insert_statement
65+
[db2]: https://www.ibm.com/docs/en/db2/9.7?topic=statements-insert
66+
[hive]: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-InsertingvaluesintotablesfromSQL
67+
[mariadb]: https://mariadb.com/kb/en/insert/
68+
[mysql]: https://dev.mysql.com/doc/refman/8.0/en/insert.html
69+
[n1ql]: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/insert.html
70+
[pl/sql]: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/INSERT.html
71+
[postgresql]: https://www.postgresql.org/docs/current/sql-insert.html
72+
[redshift]: https://docs.aws.amazon.com/redshift/latest/dg/r_INSERT_30.html
73+
[spark]: https://spark.apache.org/docs/latest/sql-ref-syntax-dml-insert-table.html
74+
[sqlite]: https://www.sqlite.org/lang_insert.html
75+
[transact-sql]: https://docs.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql?view=sql-server-ver16

0 commit comments

Comments
 (0)