Understanding SQL Data Types When You Are Just Starting
Summary: every column has a data type that says what kind of value it holds, such as whole numbers, text or dates. Good choices stop bad data getting in and make sorting and calculations behave correctly. The names vary between databases, but the families are the same.
In short: whole numbers in integer columns, money in exact decimal columns, text in text columns, dates in date or timestamp columns. Never store dates or numbers as text.
The main families
| Family | Common names | Holds | Example |
|---|---|---|---|
| Whole numbers | INTEGER, INT, BIGINT, SMALLINT | Counts, ids, years | 42 |
| Exact decimals | NUMERIC, DECIMAL | Money, measurements needing exact digits | 19.99 |
| Approximate numbers | REAL, FLOAT, DOUBLE PRECISION | Scientific values where tiny rounding is fine | 3.14159 |
| Text | TEXT, VARCHAR(n), CHAR(n) | Names, descriptions | 'Ana' |
| Dates and times | DATE, TIME, TIMESTAMP | Birthdays, order times | '2026-11-23' |
| True or false | BOOLEAN | Yes or no flags | TRUE |
| Binary | BLOB, BYTEA, VARBINARY | Raw bytes such as small files | (bytes) |
Why the type matters
It keeps data clean. A DATE column rejects "next Tuesday-ish" in databases that check types strictly.
It makes sorting correct. As text, "10" sorts before "9", because "1" comes before "9". As numbers, 9 comes before 10.
It makes calculations correct. Approximate types such as FLOAT can store 0.1 + 0.2 as a value very slightly different from 0.3. For money, use NUMERIC or DECIMAL, or store whole cents in an integer.
It saves space. A small integer takes far less room than a long piece of text.
Differences between databases
The same idea can have different names:
| Idea | PostgreSQL | MySQL | SQLite |
|---|---|---|---|
| Text of any length | TEXT | TEXT | TEXT |
| Text with a maximum | VARCHAR(100) | VARCHAR(100) | Accepted, but length not enforced |
| True or false | BOOLEAN | BOOLEAN (stored as a tiny integer) | Usually INTEGER 0 or 1 |
| Date and time | TIMESTAMP, TIMESTAMPTZ | DATETIME, TIMESTAMP | Stored as text or numbers |
SQLite is relaxed about types: it lets you store a value of almost any kind in almost any column, unless you declare the table as STRICT in newer versions. That is friendly for learning but hides mistakes, so be extra careful there.
Choosing types for a small table
CREATE TABLE products (
id INTEGER PRIMARY KEY,
name VARCHAR(200) NOT NULL,
price NUMERIC(10, 2) NOT NULL,
in_stock BOOLEAN NOT NULL DEFAULT TRUE,
added_on DATE NOT NULL
);
NUMERIC(10, 2) means up to ten digits in total, two of them after the decimal point: plenty for prices.
Dates and time zones
A timestamp records a moment. Some types also store or convert time zones (PostgreSQL's TIMESTAMPTZ, for example), others do not. A safe beginner habit: store moments in UTC (Coordinated Universal Time) and convert to local time only when showing them to people.
Common slips
- Storing phone numbers as integers. Leading zeros vanish and "+" cannot be stored; phone numbers are text.
- Storing dates as text like "23/11/2026", which sorts wrongly and means different things in different countries. Use a DATE type, or at least the year-month-day text format.
- Using FLOAT for money.
- Making every text column VARCHAR(255) without thinking. Choose limits that suit the data, or use TEXT where your database treats it efficiently.
Next steps
Revisit your practice tables from tables, rows and columns and check that every column has a sensible type.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.