Data Types

Basic SQL
≈ 2 min read

A column stores values of a specific type

When a table is created, every column is assigned a data type. It determines which values are valid and which operations the database can perform correctly. An age is naturally stored as a number, a price as an exact decimal value, and a registration date as a date or timestamp.

CREATE TABLE products (
    id INTEGER,
    name VARCHAR(100),
    price DECIMAL(10, 2),
    available BOOLEAN
);

In the example, the identifier is stored as an integer, the name as a string with a maximum length, the price as a decimal value with two fractional digits, and product availability as a boolean.

Main groups of types

  • Integer types — for counters, identifiers, and other values without a fractional part.
  • Exact decimal types — for money and other values where predictable precision matters.
  • String types — for text of different lengths.
  • Date and time types — for calendar dates, times, and timestamps.
  • Boolean values — for flags such as “active / inactive”.
Type names and exact capabilities depend on the database system. For example, PostgreSQL, MySQL, and other systems offer different sets of integer and string types. First choose the right semantic category, then check the exact type in the documentation for your database.