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- Question 1easy
In the shop model, what is
orders.customer_id? - Question 2medium
Orders contain many products, and products appear in many orders. How should this be modelled?
- Question 3medium
Why do warehouses often use a surrogate key instead of a customer's email as the key?
- Question 4easy
Each employee has exactly one ID card, and each card belongs to one employee. What's the cardinality?
- Question 5easy
In the shop model, which is an entity and which is an attribute?
Entities, keys, and relationships
Entities, keys, and relationships
Entities, keys, and relationships
Entities, keys, and relationships
Entities, keys, and relationships
7 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.