---
title: "Naming Conventions"
description: "Consistent naming rules for tables, columns, indexes, and constraints."
---

> Documentation Index
> Fetch the complete documentation index at: https://codex.mirio.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Naming Conventions

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

```sql
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](https://codex.mirio.dev/databases/table-design/timestamps/) for the details.

Source: https://codex.mirio.dev/databases/table-design/conventions/index.mdx
