Hondus
Hondus

Reputation: 402

Simple database for product order

I want to make a simple database to order products, like chips/drinks (as full product, without any specific info about product just name and price for unit)

I designed this but I'm not sure if it's good:

**Person:**
id
username
name
password
phone
email
street
zip

**order:**
id
person_id
product_id
date
quantity (neccessary?)
status (done or not)

**product:**
id
name
price

relations: [person] 1 --- 1 [order] 1 --- many [product] (I'm not sure about relations and fields)

Upvotes: 0

Views: 2556

Answers (2)

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

It seems that in your way you are going to end up in orders containing a single product (even if you use the quantity)

I would modify the Order table:

**order:**
id
person_id
date
status (done or not)

And I would add a new table:

**OrderDetails**
id
order_id
product_id
quantity

You may check out for db normalization. You should add columns to a table that are directly related to the table. For instance date in the order is valid, because it refers to the order it was made. On the other hand it wouldn't be valid in the person table (unless it was referring to the person join date). So, similarly the quantity refers to the product in the order (thus in OrderDetails) not in the Order or the Product.

Upvotes: 3

Dani
Dani

Reputation: 181

You will probably need an intermediate table between order and product, so you can add many times same order to different products

Upvotes: 0

Related Questions