光泉鮮乳 936ml
光泉鮮乳
2026/09/22 放進冰箱
2026/09/30 到期
剩下 1 瓶
Food
├── name
├── barcode
├── quantity
├── expiration_date
└── added_at
來複習一下資料庫 ...
實體 Entity
│
├── 屬性 Attribute
│
└── 關係 Relationship
光泉鮮乳 A
品牌:光泉
名稱:光泉鮮乳
Barcode:471xxxxxxx
光泉鮮乳 B
品牌:光泉
名稱:光泉鮮乳
Barcode:471xxxxxxx
┌────────────────────────┐
│ Product │
├────────────────────────┤
│ id │
│ barcode │
│ name │
│ brand │
│ category │
└────────────────────────┘
光泉鮮乳 A
放入冰箱:9/22
到期: 9/27
數量: 1
光泉鮮乳 B
放入冰箱:9/22
到期: 10/01
數量: 1
┌────────────────────────┐
│ InventoryItem │
├────────────────────────┤
│ id │
│ product_id │
│ quantity │
│ added_at │
│ expiration_date │
│ status │
└────────────────────────┘
InventoryItem #101
product_id = 1
quantity = 1
added_at = 2026-09-22
expiration_date= 2026-09-27
status = IN_STOCK
InventoryItem #102
product_id = 1
quantity = 1
added_at = 2026-09-22
expiration_date= 2026-10-01
status = IN_STOCK
Product
「光泉鮮乳」
│
│
1 │
│
│
N │
┌────────┴────────┐
│ │
▼ ▼
InventoryItem InventoryItem
#101 #102
9/27 到期 10/01 到期
One-to-Many Relationship,1:N
Product
────────────────────────
id 1
barcode 471xxxxxxx
name 光泉鮮乳
brand 光泉
InventoryItem
────────────────────────────────────
id product_id expiration_date
101 1 2026-09-27
102 1 2026-10-01
product_id 都指向了 商品表內的一樣商品,透過的 product_id = 1 這個 product_id 就是外部鍵 Foreign Key
Product
────────────────
PK id = 1
name = 光泉鮮乳
▲
│
│ FK product_id
│
┌─────┴─────────────┐
│ │
│ │
InventoryItem InventoryItem
──────────────── ────────────────
PK id = 101 PK id = 102
FK product_id=1 FK product_id=1
expire=9/27 expire=10/01