On this page
  1. CREATE TABLE
  2. Syntax & Overview
  3. Notes & Best Practices
  4. Example

CREATE TABLE

Prev: `ON CONFLICT` | Up: clauses | Next: `CREATE INDEX`
Rel: clauses, SQL Query Execution Lifecycle
Ref: PostgreSQL — SQL Commands
Tags: #public #databases #sql #clauses #tier/core


Syntax & Overview

CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT NOT NULL);

Defines table schema and integrity constraints.

Notes & Best Practices

Example

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

Linked from

Related notes