Create a basic table with primary key and defaults.

Section: Schemas, Tables, and Core DDL

Create table

sql
sql
CREATE TABLE public.users (
  user_id bigserial PRIMARY KEY,
  email text NOT NULL UNIQUE,
  created_at timestamptz NOT NULL DEFAULT now()
);
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Schemas, Tables, and Core DDL
Create identity column
Use a SQL-standard identity column instead of serial.
OpenIn sheetsqlsame section
Create schema
Create a namespace for objects.
OpenIn sheetsqlsame section
Add column
Add a nullable column to an existing table.
OpenIn sheetsqlsame section
Set column default
Change a column default value.
OpenIn sheetsqlsame section
Set NOT NULL
Enforce non-nullability on a column.
OpenIn sheetsqlsame section
Add check constraint
Add a named CHECK constraint.
OpenIn sheetsqlsame section