Skip to main content
⚡ OpenDevDocs
Database Fundamentals
databasedatabase-fundamentalsCore ConceptBeginner

Database Columns & Data Types

Learn about table columns, fields, data type selection (integers, varchars, booleans, timestamps, JSONB, UUIDs), and column constraints.

Verified: 2026-09-30
Platforms:
nodelinux
#database#sql#columns#data-types#schema

What is a Column?

A Column (also referred to as a Field or Attribute) defines a specific characteristic or property of the entity represented by the table. Every column is assigned a strict Data Type and optional Constraints.


Common SQL Data Types

Data Type CategoryPostgreSQL / SQL TypeExample Usage
IntegersSMALLINT, INT, BIGINTCounters, IDs, quantity
Decimals / MoneyNUMERIC(10, 2), DECIMALFinancial balances, currency (exact precision)
Floating PointREAL, DOUBLE PRECISIONScientific calculations (inexact precision)
Text StringsVARCHAR(N), TEXTUsernames, descriptions, blog posts
BooleansBOOLEANFlags (is_active, is_verified)
Dates & TimesDATE, TIMESTAMPTZTimestamps with timezone support
IdentifiersUUIDUniversally Unique Identifiers
Semi-StructuredJSONBDynamic metadata, third-party webhook payloads

Column Constraints

Constraints enforce rules on the values stored in a column:

  • NOT NULL: Disallows missing/null values.
  • UNIQUE: Guarantees all non-null values in the column are distinct across the table.
  • DEFAULT <value>: Automatically supplies a fallback value if none is provided during insertion.
  • CHECK (<condition>): Enforces custom logical validations (e.g. CHECK (age >= 18) or CHECK (price > 0)).
CREATE TABLE products (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    sku VARCHAR(30) NOT NULL UNIQUE,
    title VARCHAR(150) NOT NULL,
    price NUMERIC(10, 2) NOT NULL CHECK (price >= 0),
    stock_quantity INT NOT NULL DEFAULT 0 CHECK (stock_quantity >= 0),
    metadata JSONB DEFAULT '{}'::jsonb,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

On this page