Data Types
A column type describes intended values and operations. Enforcement and conversion rules depend on the database; SQLite normally uses flexible type affinity and also supports STRICT tables.
Choose column representations and check how the selected database enforces or coerces them.
A shop stores prices in a column of approximate floating-point numbers. One day the accountant adds up a thousand small payments and the total is off by a fraction of a paisa — enough to fail an audit. Another shop stores phone numbers as integers and loses every leading zero. Both mistakes were made the moment someone picked a column type.
The rule
Choose the narrowest type that honestly fits every value.
Every column has a data type. The type decides which values are allowed, how they sort and compare, and how much space they take. The database rejects values that do not fit, which is your first line of defence against bad data.
The everyday types, with names that work in most databases:
| Type | Holds | Shop example |
|---|---|---|
INTEGER / BIGINT |
whole numbers | quantity, customer_id |
DECIMAL(p, s) |
exact decimals: p digits, s after the point |
price DECIMAL(10, 2) |
REAL / FLOAT |
approximate decimals | a sensor reading |
VARCHAR(n) |
text up to n characters |
name VARCHAR(100) |
CHAR(n) |
text of exactly n characters, padded |
a 2-letter country code |
TEXT |
long text (not in every database's standard set) | a product description |
DATE, TIME, TIMESTAMP |
a day, a clock time, both together | joined_on DATE |
BOOLEAN |
true or false | is_active |
DECIMAL(10, 2) holds up to 10 digits, 2 of them after the point, so its largest value is 99999999.99. Floating-point types store numbers in binary and cannot represent many decimals exactly, which is why they are wrong for money.
Missing values are not a type: any column can hold NULL (meaning "unknown") unless you forbid it.