我的金融证券数据库架构是否正确?

时间:2020-06-02 12:59:00

标签: mysql database database-design

我目前正在使用电子表格来计算金融产品和地区之间的货币分配。下表是电子表格的一小部分,其中包含几百行数据和层次结构中的更多层:

+---------------+------------+---------------+------------+---------------+------------+---------------+------------+------------+------------+----------------+
| product_L1_id | Allocation | product_L2_id | Allocation | product_L3_id | Allocation |   region_id   | Allocation | country_id | Allocation | Net allocation |
+---------------+------------+---------------+------------+---------------+------------+---------------+------------+------------+------------+----------------+
| Bonds         | 100.0%     | Normal        | 60.0%      | Government    | 70.0%      | EMEA          | 80.0%      | UK         | 30.0%      | 10.1%          |
| Bonds         | 100.0%     | Normal        | 60.0%      | Government    | 70.0%      | EMEA          | 80.0%      | France     | 70.0%      | 23.5%          |
| Bonds         | 100.0%     | Normal        | 60.0%      | Government    | 70.0%      | North America | 20.0%      | US         | 0.0%       | 0.0%           |
| Bonds         | 100.0%     | Normal        | 60.0%      | Government    | 70.0%      | North America | 20.0%      | Canada     | 100.0%     | 8.4%           |
| Bonds         | 100.0%     | Normal        | 60.0%      | Corporate     | 30.0%      | EMEA          | 60.0%      | UK         | 80.0%      | 8.6%           |
| Bonds         | 100.0%     | Normal        | 60.0%      | Corporate     | 30.0%      | EMEA          | 60.0%      | France     | 20.0%      | 2.2%           |
| Bonds         | 100.0%     | Normal        | 60.0%      | Corporate     | 30.0%      | North America | 40.0%      | US         | 50.0%      | 3.6%           |
| Bonds         | 100.0%     | Normal        | 60.0%      | Corporate     | 30.0%      | North America | 40.0%      | Canada     | 50.0%      | 3.6%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | High yield    | 80.0%      | EMEA          | 30.0%      | UK         | 60.0%      | 5.8%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | High yield    | 80.0%      | EMEA          | 30.0%      | France     | 40.0%      | 3.8%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | High yield    | 80.0%      | North America | 70.0%      | US         | 30.0%      | 6.7%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | High yield    | 80.0%      | North America | 70.0%      | Canada     | 70.0%      | 15.7%          |
| Bonds         | 100.0%     | Foreign       | 40.0%      | Government    | 20.0%      | EMEA          | 100.0%     | UK         | 0.0%       | 0.0%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | Government    | 20.0%      | EMEA          | 100.0%     | France     | 100.0%     | 8.0%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | Government    | 20.0%      | North America | 0.0%       | US         | 70.0%      | 0.0%           |
| Bonds         | 100.0%     | Foreign       | 40.0%      | Government    | 20.0%      | North America | 0.0%       | Canada     | 30.0%      | 0.0%           |
+---------------+------------+---------------+------------+---------------+------------+---------------+------------+------------+------------+----------------+

值得我指出的是,同一product_L3可以出现在不同的product_L2下-以“政府”为例。

电子表格的主要输出是Net allocation字段,它是所有单独分配的乘积。

我想将其转换为我的第一个数据库,并且在花很多时间实现它之前,请先检查一下自己的想法。在我看来,很明显有机会使用多个表,所以我第一次尝试使用schema(?):

  • product_L1表,其中包含ID和分配列
  • product_L2表,其中包含ID和分配列
  • product_L3表,其中包含ID和分配列
  • Region表,其中包含ID和分配列
  • Country表,其中包含ID和分配列

然后,我计划在每个表中使用外键将其链接到层次结构中的上一个表。但是,以Country表为例-我认为这将需要每个国家重复多次,并且每条记录都必须具有所有先前表中的外键,以便查询得出{ {1}}。这是正确/有效吗?有其他不同的思考方式吗?我已经读过有关嵌套集的信息,但是不确定它们是否是这里的最佳解决方案?

这不会是多个用户的数据库-仅我一个。

1 个答案:

答案 0 :(得分:1)

您的数据库设计对我来说很好。

  • product_l1(product_l1_id,分配)
  • product_l2(product_l2_id,分配)
  • product_l3(product_l3,分配)
  • 区域(region_id,分配)
  • 国家(country_id,分配)

一个人可能会说产品是一种产品,一个带有产品级别指示器的表就足够了,但是我认为带有三个表的这种模型是合适的。例如,它保证不能将1级产品用作2级产品。

缺少包含要显示的组合的表:

  • 组合(product_l1_id,product_l2_id,product_l3_id,region_id,country_id)

更新:

再次查看数据,我想到两件事。

  1. 一个国家似乎属于一个区域,因此国家表应获得一个region_id。
  2. 一个区域没有固定分配。
  3. 在示例数据中,您将不同国家/地区使用相同的组合。因此,您可能希望将此分为两个步骤。

这将得到如下内容:

  • product_l1(product_l1_id,名称,分配)
  • product_l2(product_l2_id,名称,分配)
  • product_l3(product_l3,名称,分配)
  • 区域(region_id,名称)
  • 国家(国家/地区ID,名称,region_id,分配)
  • product_combination(product_combination_id,product_l1_id,product_l2_id,product_l3_id)
  • region_combination(product_combination_id,region_id,分配)
  • 最终组合(product_combination_id,country_id)
相关问题