Online shop ERD
Member, order, order item and product. The many-to-many between orders and products is resolved by the order item entity, the classic database-design exercise.
The diagram
Reading it step by step
- 'Member' has 3 attributes, primary key member_id.
- 'Orders' has 3 attributes, primary key order_id, foreign key member_id.
- 'OrderItem' has 4 attributes, primary key item_id, foreign key order_id, product_id.
- 'Product' has 3 attributes, primary key product_id.
- Each 'Member' relates to zero or more 'Orders'; each 'Orders' to exactly one 'Member' (places).
- Each 'Orders' relates to one or more 'OrderItem'; each 'OrderItem' to exactly one 'Orders' (contains).
- Each 'Product' relates to zero or more 'OrderItem'; each 'OrderItem' to exactly one 'Product' (appears_in).
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Member | Entity | holds member_id, email, name · → Orders(places) |
| Orders | Entity | holds order_id, member_id, ordered_at · → OrderItem(contains) · ← Member |
| OrderItem | Entity | holds item_id, order_id, product_id, quantity · ← Orders, Product |
| Product | Entity | holds product_id, title, price · → OrderItem(appears_in) |
Symbols used here
| Symbol | Meaning |
|---|---|
| Entity | A thing to store: name on top, attributes below. |
| Primary key (PK) | The attribute that identifies one row; underlined. |
| Foreign key (FK) | An attribute pointing to another entity's key. |
| Exactly one | Two short bars at the line end. |
| Zero or many | A crow's foot and a circle. |
| One or many | A crow's foot and a bar. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Online shop ERD
erDiagram
Member {
int member_id PK
varchar email
varchar name
}
Orders {
int order_id PK
int member_id FK
date ordered_at
}
OrderItem {
int item_id PK
int order_id FK
int product_id FK
int quantity
}
Product {
int product_id PK
varchar title
int price
}
Member ||--o{ Orders : places
Orders ||--|{ OrderItem : contains
Product ||--o{ OrderItem : appears_in