SQLite Syntax Quick Reference
SQLite is a lightweight, serverless, self-contained SQL database engine. While its syntax is similar
to standard SQL, there are some differences. This guide covers basic to advanced SQLite syntax
for quick reference.
Data Types in SQLite
Type Description
NULL Represents a missing value.
INTEGER Signed integer (1, 2, 3, 4, 6, or 8 bytes).
REAL Floating-point value (8-byte IEEE).
TEXT Text string, stored using database encoding (UTF-8, UTF-16).
BLOB Binary data stored exactly as input.
Basic Commands
CREATE TABLE
CREATE TABLE table_name (
column1 datatype PRIMARY KEY,
column2 datatype NOT NULL,
column3 datatype DEFAULT value
);
INSERT
INSERT INTO table_name (column1, column2)
VALUES (value1, value2);
SELECT
SELECT column1, column2 FROM table_name
WHERE condition;
UPDATE
UPDATE table_name
SET column1 = value1
WHERE condition;
DELETE
DELETE FROM table_name WHERE condition;
Joins in SQLite
SELECT table1.column1, table2.column2
FROM table1
INNER JOIN table2 ON table1.id = table2.id;
Common SQLite Functions
Function Example Description
Length SELECT LENGTH('Hello'); Returns the length of a string.
Upper SELECT UPPER('hello'); Converts text to uppercase.
Lower SELECT LOWER('HELLO'); Converts text to lowercase.
Date SELECT DATE('now'); Returns the current date.
Datetime SELECT DATETIME('now'); Returns the current date and time.
Transactions
BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;