TECHNOLOGIESTieInn Technologies

Entities, keys, and relationships

Data Modelling · 12 questions

Short notes

Key idea

A data model describes the things a business cares about (entities), the facts we store about them (attributes), how each row is identified (keys) and how entities connect (relationships).

Syntax

  • Entity → table: Customer, Order, Product.
  • Primary key (PK): uniquely identifies a row; never NULL, never repeated.
  • Foreign key (FK): a column pointing to another table's PK (orders.customer_id).
  • Natural key: a real-world identifier (email, PAN). Surrogate key: a generated number with no meaning.
  • Cardinality: one-to-one, one-to-many, many-to-many.
  • Many-to-many needs a bridge table (order_items between orders and products).

Example

One customer places many orders: orders.customer_id → customers.customer_id (one-to-many). One order has many products and one product appears in many orders, so order_items(order_id, product_id, qty) resolves the many-to-many.

Traps

  • Natural keys change (people change email); surrogate keys don't.
  • Storing a list in one column ("P1,P7,P9") instead of a bridge table makes joins and counts painful.
  • Missing FK constraints let orphan rows creep in.
  • Composite keys must be unique as a combination, not column by column.

Want the full lesson with step-by-step examples, a project and a certificate? Data Modelling course, ₹120 →

Questions

5 free questions
5 questions

    Entities, keys, and relationships

  1. Question 1easy

    In the shop model, what is orders.customer_id?

  2. Entities, keys, and relationships

  3. Question 2medium

    Orders contain many products, and products appear in many orders. How should this be modelled?

  4. Entities, keys, and relationships

  5. Question 3medium

    Why do warehouses often use a surrogate key instead of a customer's email as the key?

  6. Entities, keys, and relationships

  7. Question 4easy

    Each employee has exactly one ID card, and each card belongs to one employee. What's the cardinality?

  8. Entities, keys, and relationships

  9. Question 5easy

    In the shop model, which is an entity and which is an attribute?

7 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.