Establishing Naming Conventions: Best Practices for PostgreSQL
Learn professional naming conventions for PostgreSQL to keep your database readable. Discover snake_case, consistent key naming, and schema design standards.

Previously in this course, we explored handling timestamps. While that lesson focused on managing temporal data, today we pivot to the "architecture of readability": establishing naming conventions that make your schema a pleasure to work with, rather than a cryptic puzzle.
In production environments, a database schema is documentation in itself. If your naming is inconsistent, you'll eventually encounter technical debt that slows down development and increases the risk of bugs.
Why Naming Conventions Matter
In PostgreSQL, identifiers (table names, column names) are case-insensitive by default unless you wrap them in double quotes. This causes common headaches: UserAccount might be treated as useraccount, while "UserAccount" is treated literally. To avoid these traps, the industry standard is to use snake_case for everything.
The Core Principles
- Consistency: If you name a primary key
idin one table, name itidin all tables. - Clarity: Avoid abbreviations that require a decoder ring (e.g., use
customer_emailinstead ofcust_eml). - Plural vs. Singular: Use singular nouns for table names (
customerinstead ofcustomers) to align with the concept that a table represents a single entity definition.
Implementing Consistent Key Naming
Foreign keys are the glue of your relational model. If your naming is inconsistent, your JOIN queries will become difficult to read.
- Primary Keys: Always use
id. It is simple, standard, and works perfectly with PostgreSQL’sSERIALorUUIDtypes. - Foreign Keys: Use the pattern
[table_name]_id. For example, if you are referencing thecustomertable from anordertable, the column should becustomer_id.
Worked Example: Refactoring the Store Schema
Let's look at how we apply these standards to our running store project. Imagine we are cleaning up a messy schema:
SQL-- BAD: Inconsistent and mixed case CREATE TABLE CustomerData ( CustID INT PRIMARY KEY, User_Name TEXT, emailAddress TEXT ); CREATE TABLE Orders ( oid INT PRIMARY KEY, c_id INT REFERENCES CustomerData(CustID) ); -- GOOD: Clean, consistent, and readable CREATE TABLE customer ( id INT PRIMARY KEY, username TEXT NOT NULL, email_address TEXT NOT NULL ); CREATE TABLE "order" ( id INT PRIMARY KEY, customer_id INT REFERENCES customer(id) );
Note: order is a reserved keyword in SQL. If you must use it as a table name, you must quote it, but it is often better to use store_order to avoid needing quotes entirely.
Best Practices for Schema Design
Beyond simple casing, here is how you ensure your database remains professional as it grows:
| Element | Convention | Example |
|---|---|---|
| Table Names | Lowercase snake_case | product_category |
| Column Names | Lowercase snake_case | created_at |
| Primary Keys | id | id |
| Foreign Keys | [table]_id | product_id |
| Boolean Flags | is_[state] | is_active |
Hands-on Exercise
Open your PostgreSQL terminal or pgAdmin query tool. Review the customers and products tables you created in earlier lessons.
- Write an
ALTER TABLEstatement (or recreate the table) to rename any non-compliant columns tosnake_case. - Ensure all foreign key columns end in
_id. - Rename any ambiguous columns (like
data) to descriptive names (likecustomer_bio).
Common Pitfalls
- Reserved Keywords: Never name a column
user,order, ordate. PostgreSQL will fight you on these. Useapp_userororder_dateinstead. - Over-abbreviation:
p_idis ambiguous. Is itproduct_idorpayment_id? Always favor explicit, full words over brevity. - Quoting Identifiers: Avoid using double quotes for identifiers at all costs. It forces you to use quotes every time you query the table, which is a massive productivity killer. Stick to lowercase letters and underscores.
FAQ
Q: Should I use id or [table]_id for the primary key?
A: Use id for the primary key of the table itself. Use [table]_id only when that ID appears in another table as a foreign key.
Q: Is it okay to use camelCase?
A: While some teams do, PostgreSQL converts unquoted identifiers to lowercase. If you use userName, it will be stored as username. Mixing case styles leads to confusion; stick to snake_case for consistency.
Recap
We’ve established that professional naming is not just about aesthetics—it’s about preventing errors and reducing cognitive load. By enforcing snake_case, using explicit names, and standardizing how we link primary and foreign keys, we’ve made our store schema robust and maintainable.
Up next: Database Documentation Standards — where we will learn how to use comments to make our schema self-documenting.
Work with me

Laravel SaaS MVP & Multi-Tenant App Development
Launch your SaaS MVP on Laravel — multi-tenant, subscription-ready, and built by the engineer behind a platform serving 10,000+ paying users.

Next.js Website & Landing Page Development
A blazing-fast, SEO-optimized website or landing page in Next.js — the kind that loads instantly and ranks. Design-to-code, done right.


