Skip to content

Naming Conventions

Consistent naming rules for tables, columns, indexes, and constraints.

Consistent names make schemas readable without documentation and let tooling (ORMs, migration tools, query builders) apply sensible defaults automatically.

Rules at a glance

Object Convention Example
Table plural snake_case users, blog_posts
Column snake_case first_name, created_at
Primary key id not user_id on the users table
Foreign key <singular_table>_id user_id, post_id
Index idx_<table>_<cols> idx_blog_posts_user_id
Unique constraint uq_<table>_<cols> uq_users_email
Check constraint ck_<table>_<desc> ck_users_email_format

Example schema

CREATE TABLE users (
  id    BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  email TEXT   NOT NULL,
  CONSTRAINT uq_users_email UNIQUE (email)
);

CREATE TABLE blog_posts (
  id         BIGINT      GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  user_id    BIGINT      NOT NULL REFERENCES users (id),
  title      TEXT        NOT NULL,
  body       TEXT        NOT NULL DEFAULT '',
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_blog_posts_user_id ON blog_posts (user_id);

Notes

Plural table names. A table is a set of rows, so users reads more naturally than user in queries: SELECT * FROM users WHERE ....

id, not users_id. The table name already provides the context; repeating it on the primary key column is noise. Foreign keys carry the table name because the context is different: user_id on blog_posts says “this references a user”.

Named constraints. Some databases auto-generate opaque names like users_email_key, which are hard to interpret in error messages and migration diffs. Explicit names (uq_users_email) make ERROR: duplicate key value violates unique constraint "uq_users_email" immediately actionable. The same naming scheme works across Postgres and SQLite.

Timestamp column names. Use the _at suffix for timestamps (created_at, updated_at, deleted_at). The type varies by database; see Timestamps for the details.

Type to search…

↑↓ navigate↵ selectEsc close