CMD Guide
HomeDatabases

Data Modeling

Step 7 in the Databases path · 5 concepts · 0 problems

0 / 5 complete

📘 Learn Data Modeling from zero

Data modeling is the discipline of deciding what data you will store and how the pieces relate, before you build the database. Think of it as the blueprint an architect draws before anyone pours concrete: you would never build a house by stacking bricks ad hoc, and you should not build a database by inventing columns on the fly.

First principles. Every model is built from three primitives: entities (the nouns/things you track), attributes (the properties of each thing), and relationships (how things connect, described by their cardinality: 1:1, 1:N, or M:N).

The three levels. You refine the model in stages: a conceptual model (business-facing, technology-agnostic — just entities and relationships), a logical model (adds attributes, primary keys, foreign keys, and normalization, still vendor-neutral), and a physical model (actual tables, data types, indexes, and partitioning for a specific engine like PostgreSQL).

Worked example — a library. Conceptual: entities Member, Book, and Loan; a Member borrows Books. Because one member borrows many books and one book is borrowed by many members over time, that is an M:N relationship — so you resolve it with a Loan associative (junction) entity that also carries its own attribute, due_date. Logical: Member(member_id PK, name), Book(book_id PK, title), Loan(loan_id PK, member_id FK, book_id FK, due_date). Physical: pick BIGINT for ids, DATE for due_date, and add an index on Loan.member_id for fast per-member lookups.

Key insight: a good data model is access-pattern-aware structure decided before code — get the entities, cardinalities, and level of normalization right, and queries become simple; get them wrong, and no amount of query tuning saves you.

✨ Added by the guide to build intuition — not from the source course.

🎯 Guided practice

  1. Easy — Identify cardinality and resolve it.

    Problem: A blogging platform has Authors and Posts. Each post is written by exactly one author; an author can write many posts. Model this.

    Step 1 — name entities: Author and Post.

    Step 2 — determine cardinality: one author → many posts, each post → one author. That is 1:N.

    Step 3 — apply the rule: for 1:N, place the foreign key on the "many" side. No junction table is needed.

    Answer: Author(author_id PK, name) and Post(post_id PK, title, author_id FK). The author_id living on Post is the whole pattern.

  2. Medium — Normalize to 3NF and spot the M:N.

    Problem: An orders sheet has columns: order_id, customer_name, customer_email, product1, product2, product3, product_category. Redesign it properly.

    Step 1 — 1NF (atomic values, no repeating groups): the product1/2/3 columns are a repeating group. Split products into their own rows/entity. Now an order can contain many products and a product can appear in many orders → this is an M:N relationship.

    Step 2 — resolve M:N with a junction table: introduce OrderItem(order_id FK, product_id FK) with a composite PK (order_id, product_id).

    Step 3 — 2NF then 3NF (remove partial, then transitive dependencies): customer_email depends on the customer, not the order, so extract Customer. product_category depends on the product (a transitive dependency via the product, not on the order key), so it belongs on Product.

    Answer: Customer(customer_id PK, name, email), Order(order_id PK, customer_id FK), Product(product_id PK, name, category), OrderItem(order_id FK, product_id FK, PK(order_id, product_id)).

    Core pattern learned: repeating columns → split into a new entity; M:N → junction table with a composite key; an attribute that depends on something other than the whole key → move it to where its key lives.

✨ Added by the guide — work these before the full problem set.

Lessons in this topic

🧠 Review & recall

Active recall is what moves a topic into long-term memory. Flip each card before revealing, then test yourself — your results are saved on this device.

Flashcard
What is data modeling, and what is its core purpose?
tap to reveal →
Data modeling is the process of defining and organizing data elements and their relationships within a database, before the database is built. It provides a blueprint that ensures data consistency, accuracy, and efficiency, making data easier to manage and retrieve.
💡 Blueprint before bricks — decide structure before you build.
Flashcard
What are the three levels of data modeling, and how does detail increase across them?
tap to reveal →
Conceptual (low detail: just core entities and relationships, technology-independent), Logical (medium detail: adds attributes, data types, primary/foreign keys, and normalization, still technology-agnostic), and Physical (high detail: DBMS-specific data types, indexing, partitioning, and storage).
💡 CLP ladder — Concept → Logic → Physical, detail climbs each rung.
Flashcard
What distinguishes a logical data model from a conceptual one?
tap to reveal →
A conceptual model only names entities and their relationships with no attributes or data types. A logical model adds attributes with data types, specifies primary and foreign keys to establish relationships, and applies normalization to minimize redundancy — while remaining independent of any specific DBMS.
💡 Logical = conceptual + attributes + keys + normalization (still vendor-neutral).
Flashcard
What makes the physical model different from the logical model?
tap to reveal →
The physical model transforms the logical model to fit a specific DBMS: it uses concrete data types (e.g., VARCHAR(255), INT in SQL), adds indexing and partitioning for performance, maps relationships to real tables/columns/foreign keys, and includes storage details like file structures.
💡 Physical = where the DBMS gets named (VARCHAR, indexes, disk).
Flashcard
What are the ordered steps of the data modeling process?
tap to reveal →
Requirements Gathering → Define Entities and Relationships → Create the Conceptual Model → Design the Logical Model → Build the Physical Model → Validate the Model → Implement and Refine. Each step refines toward a model that meets needs, maintains integrity, and optimizes performance.
💡 Gather, define, then C-L-P, then validate, implement, refine.
Flashcard
In a 1:N relationship (e.g., one Author writes many Posts), where does the foreign key go?
tap to reveal →
On the 'many' side. For Author(author_id PK, name) and Post(post_id PK, title, author_id FK), the author_id foreign key lives on Post. No junction table is needed for 1:N.
💡 FK lives on the 'many' side; junction tables are only for M:N.
Flashcard
What are the key best-practice pitfalls to avoid in data modeling?
tap to reveal →
Over-normalization (excessive normalization causes complex joins that hurt query performance), under-documenting (makes the model hard to maintain or troubleshoot), and ignoring future requirements (forces costly restructuring later). Denormalize judiciously when performance is critical.
💡 Don't over-normalize, don't under-document, don't ignore the future.
Q1. At which level of data modeling do you first introduce attributes, data types, primary keys, and foreign keys?
Q2. You are modeling an e-commerce platform where each customer can place multiple orders, but each order belongs to exactly one customer. How is this relationship resolved?
Q3. An orders sheet has columns product1, product2, product3 for the items in each order. What does this signal, and how is it fixed during modeling?
Q4. Which statement best describes the physical data model?
Q5. According to the best practices, what is the danger of over-normalization?