ERD Naming Conventions for Tables and Columns
Best practices for naming tables and columns in ER diagrams. Covers snake_case, plural table names, foreign key naming patterns, and avoiding reserved words.
Detailed Explanation
Why Naming Conventions Matter
Consistent naming conventions make your database schema readable, maintainable, and less error-prone. When multiple developers work on the same database, agreed-upon conventions prevent confusion and reduce bugs.
Table Naming Rules
| Rule | Good | Bad |
|---|---|---|
| Use plural nouns | users, orders |
user, order |
| Use snake_case | order_items |
OrderItems, orderitems |
| Be descriptive | user_preferences |
prefs, up |
| Avoid reserved words | user_orders |
order (SQL reserved) |
Column Naming Rules
- Use snake_case:
first_name,created_at,is_active - Primary keys: Name them
id(simple) or{table_singular}_id(explicit) - Foreign keys: Use
{referenced_table_singular}_id— e.g.,user_idreferencesusers.id - Boolean columns: Prefix with
is_,has_, orcan_— e.g.,is_active,has_verified_email - Timestamps: Use
created_at,updated_at,deleted_at
Junction Table Naming
For many-to-many relationships, the junction table should combine both table names in alphabetical order:
users+roles→roles_users(alphabetical) oruser_roles(contextual)courses+students→course_enrollments(semantic name preferred)
Avoid These Pitfalls
- Abbreviations:
usr,addr,qty— spell them out unless universally understood - Prefixes:
tbl_users,t_orders— the table type is already clear from context - Mixed conventions: Mixing
camelCaseandsnake_casein the same schema - Generic names:
data,info,details— these convey no meaning
Applying in the ERD Editor
When you create entities in the ERD editor, name the table in the properties panel. The tool passes table and column names directly into the generated SQL, so following conventions here means your exported CREATE TABLE statements are production-ready from the start.
Use Case
You are establishing coding standards for a new team or onboarding new developers. Having clear naming conventions documented and applied from the ERD design phase ensures consistency from the initial schema design through application code and ORM models.