Skip to content

SQL syntax ​

SQL statements describe queries, data changes and schema operations. Keywords and built-in function names ignore ASCII case; the accepted syntax is defined by each statement or function page.

Identifiers and strings ​

Quote identifiers with double quotes or backticks. Quote strings with single quotes. Double a quote character to include it inside that quoted value.

sql
SELECT 'It''s SQL' AS message,
       hex(X'4142') AS bytes,
       CAST('12.50' AS Decimal(18, 2)) AS amount
FORMAT csv;
text
"It's SQL","4142",12.50

Literals and expressions ​

Literals include integers, decimal and exponent spellings, strings, X-prefixed blobs, TRUE, FALSE and NULL. Parentheses make expression grouping explicit. CAST applies a declared type's conversions and range checks.

Use the operators reference for arithmetic, comparison, membership, text, JSON and full-text operators.

Statements and comments ​

Semicolons separate statements in a request. Comments use -- to the end of a line or /* ... */ for a block.

After INSERT FORMAT, the remaining bytes are input data rather than SQL. Put input SETTINGS before FORMAT and send later verification SQL in another request.

Parameters and interfaces ​

The embedded API and native parameter frames accept positional bindings. Missing bindings are errors. The ordinary HTTP SQL interface does not accept bound parameters.

Server commands USE, SHOW and SET add managed database selection and settings. The embedded engine does not provide those service commands.

Transactions ​

BEGIN starts a transaction, COMMIT keeps its changes and ROLLBACK undoes them. SAVEPOINT, RELEASE and ROLLBACK TO create nested undo scopes. Native connections retain transaction state; HTTP transaction statements must share one request.

See transactions for a complete example.

Triggers ​

BEFORE, AFTER and INSTEAD OF triggers can have WHEN conditions and statement bodies between BEGIN and END. Separate statements inside a trigger body with semicolons. Recursive trigger execution requires recursive_triggers.

Introspection ​

PRAGMA table_info, table_xinfo, index_list, index_info, index_xinfo, foreign_key_list and database_list expose schema information. Behavior flags include foreign_keys, defer_foreign_keys and recursive_triggers.

PRAGMA max_threads accepts integers from 0 through 64 for a connection. Zero selects automatically and one keeps execution serial. integrity_check and quick_check currently return a fixed ok row without validating storage or indexes. Unknown pragmas return no result.

Maintenance and copies ​

ANALYZE collects statistics for planning. VACUUM INTO writes a consistent copy of main and requires autocommit, UTF-8 source storage and no WITHOUT ROWID user tables. The destination must be absent or empty. A schema qualifier does not select another source.

Plain VACUUM and REINDEX are accepted without performing work. See database copies for the copy procedure.