Data types: numbers, text, dates
Choose the right kind of column for each piece of information.
Lesson 8 of 33 · about 12 minutes
The lesson
In a kitchen you keep soup in a pot and spoons in a drawer. Each column in a table is a container too, and its type says what belongs in it. Choosing the right type keeps data tidy and makes sorting and maths work properly.
| Type | Holds | Bookshop examples |
|---|---|---|
INTEGER | Whole numbers | id, stock, published_year |
REAL | Numbers with decimals | price (12.99) |
TEXT | Words and characters | title, name, city |
Dates are stored as text in the format 'YYYY-MM-DD', like '2025-07-02'. Because the biggest unit comes first, they sort in the right order.
Yes/no values are stored as INTEGER: 1 for yes, 0 for no. A column like in_stock holds 1 or 0.
Our practice database is SQLite, the most widely used database in the world. It's built into every phone. Other databases such as PostgreSQL and MySQL have a few extra type names you'll see at work:
| You may also see | Means |
|---|---|
VARCHAR(100) | Text up to 100 characters |
DECIMAL(10, 2) | Exact numbers with 2 decimal places, good for money |
DATE, TIMESTAMP | Dates, and dates with times |
BOOLEAN | true or false |
The idea is the same everywhere: pick the container that matches the thing.
- INTEGER for whole numbers, REAL for decimals, TEXT for words.
- Store dates as text in YYYY-MM-DD order so they sort correctly.
- Store yes/no as INTEGER 1 or 0. Other databases add types like VARCHAR, DECIMAL, DATE and BOOLEAN.