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

FamilyCommon namesHoldsExample
Whole numbersINTEGER, INT, BIGINT, SMALLINTCounts, ids, years42
Exact decimalsNUMERIC, DECIMALMoney, measurements needing exact digits19.99
Approximate numbersREAL, FLOAT, DOUBLE PRECISIONScientific values where tiny rounding is fine3.14159
TextTEXT, VARCHAR(n), CHAR(n)Names, descriptions'Ana'
Dates and timesDATE, TIME, TIMESTAMPBirthdays, order times'2026-11-23'
True or falseBOOLEANYes or no flagsTRUE
BinaryBLOB, BYTEA, VARBINARYRaw 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:

IdeaPostgreSQLMySQLSQLite
Text of any lengthTEXTTEXTTEXT
Text with a maximumVARCHAR(100)VARCHAR(100)Accepted, but length not enforced
True or falseBOOLEANBOOLEAN (stored as a tiny integer)Usually INTEGER 0 or 1
Date and timeTIMESTAMP, TIMESTAMPTZDATETIME, TIMESTAMPStored 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

  1. Storing phone numbers as integers. Leading zeros vanish and "+" cannot be stored; phone numbers are text.
  2. 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.
  3. Using FLOAT for money.
  4. 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.

Related pages on this site