Creating and changing tables
CREATE TABLE makes a new, empty table. You name each column and say what type of data it
holds:
CREATE TABLE price_changes (
id INTEGER,
product_id INTEGER,
changed_on DATE,
old_price DECIMAL(12, 2),
new_price DECIMAL(12, 2)
)The types you'll use most:
| Type | For | Example |
|---|---|---|
INTEGER | whole numbers, ids, counts | 42 |
DECIMAL(12, 2) | money: 12 digits, 2 after the point | 1234.50 |
VARCHAR | text | 'Leeds' |
DATE | a day | '2026-10-31' |
TIMESTAMP | a moment in time | '2026-10-31 09:30:00' |
BOOLEAN | yes or no | true |
Never store money as a floating-point number (DOUBLE, FLOAT): they can't hold 0.10 exactly, and
the pennies drift. Use DECIMAL.
ALTER TABLE changes a table that already exists:
ALTER TABLE customers ADD COLUMN vat_number VARCHARDROP TABLE price_changes deletes a table and everything in it. There's no undo.
In other databases
CREATE TABLE price_changes (id INTEGER, changed_on DATE, new_price DECIMAL(12, 2), note VARCHAR, approved BOOLEAN)CREATE TABLE price_changes (id INT, changed_on DATE, new_price DECIMAL(12, 2), note NVARCHAR(200), approved BIT)Text needs a length (NVARCHAR handles any language); yes/no is BIT.
CREATE TABLE price_changes (id INT, changed_on DATE, new_price DECIMAL(12, 2), note VARCHAR(200), approved BOOLEAN)VARCHAR needs a length. BOOLEAN is stored as a tiny number, 0 or 1.
CREATE TABLE price_changes (id INTEGER, changed_on DATE, new_price NUMERIC(12, 2), note TEXT, approved BOOLEAN)CREATE TABLE price_changes (id INT64, changed_on DATE, new_price NUMERIC, note STRING, approved BOOL)