SQL 2023 · Tables and indexes
Create a table
Define columns, a primary key, constraints and a foreign key.
CREATE TABLE orders (
id BIGINT PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users (id),
status TEXT NOT NULL DEFAULT 'new',
total NUMERIC(10, 2) NOT NULL CHECK (total >= 0),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Official SQL 2023 documentation