
How to Design a Database | Tables, Relationships, and Best Practices
A well-designed database is like a well-planned city—it saves time, avoids confusion, and scales easily as things grow.
In Episode 7 of the Database Series, we’ll walk you through the basics of designing a database from scratch, including how to:
- Define tables and relationships
- Identify entities and attributes
- Use ER diagrams to map everything visually
Let’s get started!
What Is Database Design?
Database design is the process of structuring how data is stored and connected within a system.
Why it matters:
- Ensures data is organized and easy to access
- Reduces duplication and errors
- Makes querying and reporting faster and cleaner
Step 1: Identify Entities and Attributes
What’s an Entity?
An entity is any object, person, place, or concept you want to store data about.
Examples:
- Student
- Course
- Product
- Customer
What’s an Attribute?
Attributes are the details or characteristics of an entity.
Example:
For a Student entity, attributes might be:
- student_id
- name
- date_of_birth
Step 2: Map Out Relationships Between Entities
After listing entities and attributes, the next step is to define how entities are related.
Common Relationship Types:
Relationship Type | Example | Description |
One-to-One | One user → one profile | Rare but used for tightly linked data |
One-to-Many | One teacher → many students | Most common |
Many-to-Many | Students ↔ Courses | Requires a bridge table |
Related: Primary Key vs Foreign Key in SQL
Step 3: Create an ER Diagram
An ER (Entity-Relationship) diagram visually shows:
- Entities (tables)
- Attributes (columns)
- Relationships (lines/arrows between tables)
ER Diagram Symbols:
- Entity → represented as a rectangle
- Attribute → oval shape
- Relationship → line connecting entities
Sample Mini ER Diagram
+————-+ +————–+
| Students | | Enrollments |
+————-+ +————–+
| student_id | ◄────────| student_id |
| name | | course_id |────────►+———–+
| email | | date_enrolled| | Courses |
+————-+ +————–+ +———–+
| course_id |
| name |
+———–+
Step 4: Normalize Your Data
Normalization is the process of organizing data to:
- Avoid redundancy (repeating info)
- Improve efficiency
- Ensure each table handles one type of data
You break large, complex tables into smaller ones and link them using keys.
Best Practices for Database Design
- Use meaningful table and column names
→ e.g., student_id not just id - Define primary keys for all tables
- Use foreign keys to maintain relationships
- Avoid storing repeated data (normalize!)
- Use the right data types (INT, VARCHAR, DATE, etc.)
- Plan with diagrams before writing code
- Think ahead for scalability (future-proofing)
Summary: Database Design in 4 Steps
Step | Action |
1. Define Entities | What are you storing? |
2. List Attributes | What details do you need about each entity? |
3. Map Relationships | How are entities connected? |
4. Create ER Diagram | Visualize the full structure |
A good design now prevents a messy database later.