Syntax Diagrams For SQLite

sql-stmt

sql-stmt-list sql-stmt ; EXPLAIN QUERY PLAN alter-table-stmt analyze-stmt attach-stmt begin-stmt commit-stmt create-index-stmt create-table-stmt create-trigger-stmt create-view-stmt create-virtual-table-stmt delete-stmt delete-stmt-limited detach-stmt drop-index-stmt drop-table-stmt drop-trigger-stmt drop-view-stmt insert-stmt pragma-stmt reindex-stmt release-stmt rollback-stmt savepoint-stmt select-stmt update-stmt update-stmt-limited vacuum-stmt

aggregate-function-invocation

aggregate-func ( DISTINCT expr ) filter-clause , *

alter-table-stmt

Used by: sql-stmt
ALTER TABLE schema-name . table-name RENAME TO new-table-name RENAME COLUMN column-name TO new-column-name ADD COLUMN column-def

analyze-stmt

Used by: sql-stmt
ANALYZE schema-name . table-or-index-name schema-name index-or-table-name

attach-stmt

Used by: sql-stmt
ATTACH DATABASE expr AS schema-name

begin-stmt

Used by: sql-stmt
BEGIN EXCLUSIVE TRANSACTION DEFERRED IMMEDIATE

column-def

Used by: alter-table-stmt   create-table-stmt
column-name type-name column-constraint

column-name-list

Used by: update-stmt   update-stmt-limited   upsert-clause
( column-name ) ,

column-constraint

Used by: column-def
CONSTRAINT name PRIMARY KEY DESC conflict-clause AUTOINCREMENT ASC NOT NULL conflict-clause UNIQUE conflict-clause CHECK ( expr ) DEFAULT ( expr ) literal-value signed-number COLLATE collation-name foreign-key-clause GENERATED ALWAYS AS ( expr ) VIRTUAL STORED

comment-syntax

-- anything-except-newline newline end-of-input /* anything-except-*/ */

commit-stmt

Used by: sql-stmt
COMMIT TRANSACTION END

common-table-expression

Used by: compound-select-stmt   delete-stmt   delete-stmt-limited   factored-select-stmt   insert-stmt   select-stmt   simple-select-stmt   update-stmt   update-stmt-limited
table-name ( column-name ) AS ( select-stmt ) ,

compound-operator

Used by: factored-select-stmt   select-stmt
UNION UNION INTERSECT EXCEPT ALL

compound-select-stmt

WITH RECURSIVE common-table-expression , select-core ORDER BY LIMIT expr UNION UNION ALL select-core INTERSECT EXCEPT ordering-term , OFFSET expr , expr

conflict-clause

Used by: column-constraint   table-constraint
ON CONFLICT ROLLBACK ABORT FAIL IGNORE REPLACE

cte-table-name

Used by: recursive-cte   with-clause
table-name ( column-name ) ,

create-index-stmt

Used by: sql-stmt
CREATE UNIQUE INDEX IF NOT EXISTS schema-name . index-name ON table-name ( indexed-column ) , WHERE expr

create-table-stmt

Used by: sql-stmt
CREATE TEMP TEMPORARY TABLE IF NOT EXISTS schema-name . table-name ( column-def table-constraint , ) WITHOUT ROWID , AS select-stmt

create-view-stmt

Used by: sql-stmt
CREATE TEMP TEMPORARY VIEW IF NOT EXISTS schema-name . view-name ( column-name ) AS select-stmt ,

create-trigger-stmt

Used by: sql-stmt
CREATE TEMP TEMPORARY TRIGGER IF NOT EXISTS schema-name . trigger-name BEFORE AFTER INSTEAD OF DELETE INSERT UPDATE OF column-name , ON table-name FOR EACH ROW WHEN expr BEGIN update-stmt ; END insert-stmt delete-stmt select-stmt

create-virtual-table-stmt

Used by: sql-stmt
CREATE VIRTUAL TABLE IF NOT EXISTS schema-name . table-name USING module-name ( module-argument ) ,

detach-stmt

Used by: sql-stmt
DETACH DATABASE schema-name

delete-stmt

Used by: create-trigger-stmt   sql-stmt
WITH RECURSIVE common-table-expression , DELETE FROM qualified-table-name WHERE expr

delete-stmt-limited

Used by: sql-stmt
WITH RECURSIVE common-table-expression , DELETE FROM qualified-table-name WHERE expr ORDER BY ordering-term , LIMIT expr OFFSET expr , expr

drop-index-stmt

Used by: sql-stmt
DROP INDEX IF EXISTS schema-name . index-name

drop-table-stmt

Used by: sql-stmt
DROP TABLE IF EXISTS schema-name . table-name

drop-trigger-stmt

Used by: sql-stmt
DROP TRIGGER IF EXISTS schema-name . trigger-name

drop-view-stmt

Used by: sql-stmt
DROP VIEW IF EXISTS schema-name . view-name

expr

Used by: aggregate-function-invocation   attach-stmt   column-constraint   compound-select-stmt   create-index-stmt   create-trigger-stmt   delete-stmt   delete-stmt-limited   factored-select-stmt   filter-clause   frame-spec   indexed-column   insert-stmt   join-constraint   ordering-term   over-clause   result-column   select-core   select-stmt   simple-function-invocation   simple-select-stmt   table-constraint   table-or-subquery   update-stmt   update-stmt-limited   upsert-clause   window-defn   window-function-invocation
literal-value bind-parameter schema-name . table-name . column-name unary-operator expr expr binary-operator expr function-name ( DISTINCT expr ) filter-clause over-clause , * ( expr ) , CAST ( expr AS type-name ) expr COLLATE collation-name expr NOT LIKE GLOB REGEXP MATCH expr ESCAPE expr expr ISNULL NOTNULL NOT NULL expr IS NOT expr expr NOT BETWEEN expr AND expr expr NOT IN ( select-stmt ) expr , schema-name . table-function ( expr ) table-name , NOT EXISTS ( select-stmt ) CASE expr WHEN expr THEN expr ELSE expr END raise-function

factored-select-stmt

WITH RECURSIVE common-table-expression , select-core ORDER BY LIMIT expr compound-operator ordering-term , OFFSET expr , expr

filter-clause

Used by: aggregate-function-invocation   expr   window-function-invocation
FILTER ( WHERE expr )

foreign-key-clause

Used by: column-constraint   table-constraint
REFERENCES foreign-table ( column-name ) , ON DELETE SET NULL UPDATE SET DEFAULT CASCADE RESTRICT NO ACTION MATCH name NOT DEFERRABLE INITIALLY DEFERRED INITIALLY IMMEDIATE

frame-spec

Used by: over-clause   window-defn
GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING RANGE ROWS UNBOUNDED PRECEDING expr PRECEDING CURRENT ROW expr PRECEDING CURRENT ROW expr FOLLOWING expr PRECEDING CURRENT ROW expr FOLLOWING EXCLUDE CURRENT ROW EXCLUDE GROUP EXCLUDE TIES EXCLUDE NOT OTHERS

indexed-column

Used by: create-index-stmt   table-constraint   upsert-clause
column-name COLLATE collation-name DESC expr ASC

insert-stmt

Used by: create-trigger-stmt   sql-stmt
WITH RECURSIVE common-table-expression , REPLACE INSERT OR ROLLBACK INTO ABORT FAIL IGNORE REPLACE schema-name . table-name AS alias ( column-name ) , VALUES ( expr ) , , upsert-clause select-stmt upsert-clause DEFAULT VALUES

join-clause

Used by: table-or-subquery   update-stmt   update-stmt-limited
table-or-subquery join-operator table-or-subquery join-constraint

join-constraint

Used by: join-clause
USING ( column-name ) , ON expr

join-operator

Used by: join-clause
NATURAL LEFT OUTER JOIN , INNER CROSS

literal-value

Used by: column-constraint   expr
CURRENT_TIMESTAMP numeric-literal string-literal blob-literal NULL TRUE FALSE CURRENT_TIME CURRENT_DATE

numeric-literal

digit . E e digit . digit - digit + 0x hexdigit

ordering-term

Used by: compound-select-stmt   delete-stmt-limited   factored-select-stmt   over-clause   select-stmt   simple-select-stmt   update-stmt-limited   window-defn
expr COLLATE collation-name DESC ASC NULLS FIRST NULLS LAST

over-clause

Used by: expr
OVER window-name ( base-window-name PARTITION BY expr , ORDER BY ordering-term , frame-spec )

pragma-stmt

Used by: sql-stmt
PRAGMA schema-name . pragma-name ( pragma-value ) = pragma-value

pragma-value

Used by: pragma-stmt
signed-number name signed-literal

qualified-table-name

Used by: delete-stmt   delete-stmt-limited   update-stmt   update-stmt-limited
schema-name . table-name AS alias INDEXED BY index-name NOT INDEXED

raise-function

Used by: expr
RAISE ( ROLLBACK , error-message ) IGNORE ABORT FAIL

recursive-cte

cte-table-name AS ( initial-select UNION ALL recursive-select ) UNION

reindex-stmt

Used by: sql-stmt
REINDEX schema-name . index-name table-name collation-name

release-stmt

Used by: sql-stmt
RELEASE SAVEPOINT savepoint-name

result-column

Used by: select-core   select-stmt
expr AS column-alias * table-name . *

rollback-stmt

Used by: sql-stmt
ROLLBACK TRANSACTION TO SAVEPOINT savepoint-name

savepoint-stmt

Used by: sql-stmt
SAVEPOINT savepoint-name

select-core

Used by: compound-select-stmt   factored-select-stmt   simple-select-stmt
SELECT DISTINCT result-column , ALL FROM table-or-subquery , WHERE expr GROUP BY expr HAVING expr , WINDOW window-name AS window-defn , VALUES ( expr ) , ,

select-stmt

Used by: common-table-expression   create-table-stmt   create-trigger-stmt   create-view-stmt   expr   insert-stmt   sql-stmt   table-or-subquery   with-clause
WITH RECURSIVE common-table-expression , SELECT DISTINCT result-column , ALL FROM table-or-subquery , WHERE expr GROUP BY expr HAVING expr , WINDOW window-name AS window-defn , VALUES ( expr ) , , compound-operator select-core ORDER BY LIMIT expr ordering-term , OFFSET expr , expr

signed-number

Used by: column-constraint   pragma-value   type-name
+ numeric-literal -

simple-function-invocation

simple-func ( expr ) , *

simple-select-stmt

WITH RECURSIVE common-table-expression , select-core ORDER BY LIMIT expr ordering-term , OFFSET expr , expr

table-constraint

Used by: create-table-stmt
CONSTRAINT name PRIMARY KEY ( indexed-column ) conflict-clause , UNIQUE CHECK ( expr ) FOREIGN KEY ( column-name ) foreign-key-clause ,

table-or-subquery

Used by: join-clause   select-core   select-stmt   update-stmt   update-stmt-limited
schema-name . table-name AS table-alias INDEXED BY index-name NOT INDEXED table-function-name ( expr ) , AS table-alias ( select-stmt ) ( table-or-subquery ) , join-clause

type-name

Used by: column-def   expr
name ( signed-number , signed-number ) ( signed-number )

update-stmt

Used by: create-trigger-stmt   sql-stmt
WITH RECURSIVE common-table-expression , UPDATE OR ROLLBACK qualified-table-name OR REPLACE OR IGNORE OR FAIL OR ABORT SET column-name-list = expr column-name , FROM table-or-subquery , join-clause WHERE expr

update-stmt-limited

Used by: sql-stmt
WITH RECURSIVE common-table-expression , UPDATE OR ROLLBACK qualified-table-name OR REPLACE OR IGNORE OR FAIL OR ABORT SET column-name-list = expr column-name , FROM table-or-subquery , join-clause WHERE expr ORDER BY ordering-term , LIMIT expr OFFSET expr , expr

upsert-clause

Used by: insert-stmt
ON CONFLICT ( indexed-column ) WHERE expr DO , UPDATE SET column-name-list = expr WHERE expr NOTHING , column-name

vacuum-stmt

Used by: sql-stmt
VACUUM schema-name INTO filename

window-defn

Used by: window-function-invocation
( base-window-name PARTITION BY expr , ORDER BY ordering-term , frame-spec )

window-function-invocation

window-func ( expr ) filter-clause OVER window-name window-defn , *

with-clause

WITH RECURSIVE cte-table-name AS ( select-stmt ) ,