与货币和国家相关的产品的数据库结构

时间:2015-12-05 09:19:18

标签: php mysql database laravel

在我的申请中,公司提供了许多产品/服务。

这是结构:

  

城市:

id
city_name
status
country
  

产品:

id
product_name
product_price
status
metadata
  

国家:

id
country_name
currency
status
  

货币

id
currency
symbol
code

目前,

  1. 一个国家有很多城市
  2. 一个国家/地区有一种货币
  3. 现在,每种产品在不同城市都会有不同的价格。

    如何根据城市绘制产品价格? 什么是通用结构,它可以满足所有用例?

1 个答案:

答案 0 :(得分:3)

使用规范化有帮助。

cities table:
id
name
status
country_id (id in table countries)

countries table:
id
name
currency_id (id in table currencies)
status

products table:
id
name
**    product_price ** (should be removed from this table)
status
metadata 

currencies table:
id
currency
symbol
code

product_price_in_city table:
id
city_id     (id in table cities)
product_id  (id in table products)
product_price_in_city (just a number. currency and symbol should be retrieved from table currency. using JOINs.
**'city_id ,product_id' pair should be unique.**

cities:
ID | name       | country_id
1  | 'london'   | 98
2  | 'tokyo'    | 99

countries:
ID | name       | currency_id
98 | 'england'  | 121
99 | 'japan'    | 122

currencies:
ID | name       | symbol
121| 'Pound'    | 's1'
122| 'Yen'      | 's2'

products:
ID | name 
789| 'CD'
790| 'DVD'
791| 'Floppy !!!!'

product_price_in_city:
ID  | city_id  | product_id | product_price_in_city
9988| 1        | 789        | 667788
9989| 1        | 790        | 66779988
9990| 1        | 791        | 567
9991| 2        | 790        | 776655
9992| 2        | 791        | 998877

如你所见,

CD  in London is 667788   Pound
DVD in London is 66779988 Pound
DVD in Tokyo  is 776655   Yen
相关问题