CREATE TABLE

Creates a new table with specified columns, data types, and constraints. PostgreSQL supports rich data types and constraint options.

Syntax

postgresql
CREATE TABLE name (col type constraints, ...);

Example

postgresql
CREATE TABLE users (
  id         UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  email      TEXT UNIQUE NOT NULL,
  name       TEXT NOT NULL,
  role       TEXT DEFAULT 'user' CHECK (role IN ('user', 'admin')),
  created_at TIMESTAMPTZ DEFAULT NOW()
);