SQL from Zero › Module 2: DDL: building the structure

Data types: numbers, text, dates

Choose the right kind of column for each piece of information.

Lesson 8 of 33 · about 12 minutes

Video: The right container for each thingThe narrated video for this lesson is coming soon. The lesson below covers the same ideas.

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.

TypeHoldsBookshop examples
INTEGERWhole numbersid, stock, published_year
REALNumbers with decimalsprice (12.99)
TEXTWords and characterstitle, 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 seeMeans
VARCHAR(100)Text up to 100 characters
DECIMAL(10, 2)Exact numbers with 2 decimal places, good for money
DATE, TIMESTAMPDates, and dates with times
BOOLEANtrue or false

The idea is the same everywhere: pick the container that matches the thing.

Key ideas
  • 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.

Practise

Loading practice…

Quick check

1. Which type should a price like 9.99 use in SQLite?

2. Why write dates as '2025-07-02' rather than '02/07/2025'?

3. How is a yes/no value usually stored in SQLite?