[英]SQL ecommerce database. how to relate foreign keys in same row?
您的表結構每個訂單只允許一個產品,因為您在 orders 表上有一個 productId 列。
為了允許每個訂單有多個產品,我會創建一個 orderItems 表。 每個 orderItem 都有不同的 productId,並通過 orderId 鏈接回訂單表。 像這樣:
------------------------
orders table
------------------------
orderId (primary key)
orderDate
orderTotal
customerId (foreign key)
specialInstructions
-------------------------
orderItems table
-------------------------
orderItemId (primary key)
orderId (foreign key)
productId (foreign key)
quantity
-------------------------
products table
-------------------------
productId (primary key)
productTitle
productDescription
productPrice
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.