Database Naming Conventions: Tables, Columns, and Keys
6 min read
Consistent naming in databases prevents confusion, simplifies queries, and makes schema migrations safer.
The Standard: snake_case
The overwhelming convention in SQL databases is snake_case for everything: table names, column names, indexes, and constraints.
CREATE TABLE user_accounts (
user_id SERIAL PRIMARY KEY,
first_name VARCHAR(100),
last_name VARCHAR(100),
created_at TIMESTAMP DEFAULT NOW()
);
Table Names: Singular or Plural?
| Style | Example | Used By |
|---|---|---|
| Singular | user, order | Laravel, Django |
| Plural | users, orders | Rails, many teams |
Pick one and be consistent. Both are valid.
Column Naming Rules
- Primary key:
idortable_name_id - Foreign key:
referenced_table_id(e.g.,user_id) - Timestamps:
created_at,updated_at,deleted_at - Booleans:
is_active,has_verified - Avoid reserved words: don't name columns
order,user,group
Index and Constraint Names
idx_users_email -- index
uq_users_email -- unique constraint
fk_orders_user_id -- foreign key
chk_orders_total -- check constraint
Convert to snake_case
Use the snake_case converter or case converter hub.