Diagram Desk

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

MemberPK member_id intemail varcharname varcharOrdersPK order_id intFK member_id intordered_at dateOrderItemPK item_id intFK order_id intFK product_id intquantity intProductPK product_id inttitle varcharprice intplacescontainsappears_in
ER diagram · 17 shapes

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

ShapeSymbolConnections
MemberEntityholds member_id, email, name · → Orders(places)
OrdersEntityholds order_id, member_id, ordered_at · → OrderItem(contains) · ← Member
OrderItemEntityholds item_id, order_id, product_id, quantity · ← Orders, Product
ProductEntityholds product_id, title, price · → OrderItem(appears_in)

Symbols used here

SymbolMeaning
EntityA 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 oneTwo short bars at the line end.
Zero or manyA crow's foot and a circle.
One or manyA crow's foot and a bar.

All er diagram symbols and how to draw

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

More er diagram examples

All SeewolLabs tools