Back

Tables and schemas

A table stores one kind of thing (users, posts), and each column has a data type. A schema is the overall design: tables, columns, and how they connect through keys. A primary key uniquely identifies each row; a foreign key points to a row in another table.

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email TEXT UNIQUE NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
  title TEXT NOT NULL,
  body TEXT
);

ALTER TABLE users ADD COLUMN name TEXT;

Roadmap