我正在为一家银行设计一个 SQL Server 2005 数据库,用于保存与客户(父表)及其投资组合(子表)相关的记录,每个客户都有多个投资组合。到目前为止的表格:
Client (Client_Number PK ...)
Portfolio (Portfolio_ID PK, Client_Number FK ...)
我需要包含一个表格来保存相关第三方(例如基金经理、管理员、发起人等)的记录。第三方是不确定的,并且可能会发生变化,关系类型也是如此。这些关系显然是多对多的,所以我在考虑如下附加表:
Third_Party (Third_Party_ID PK, Third_Party_Name ...)
Relationship (Relationship_ID PK, Third_Party_ID FK, Client_Number FK ...)
这可以正常工作,但是,第三方可以与 Portfolios(子表)以及 Clients(父表)相关。
例如,客户 1 有投资组合 1 和投资组合 2。客户 1 和投资组合 1 链接到发起人 1,但投资组合 2 链接到不同的发起人。
关于针对上述情况的表设计的最佳实践有什么想法吗?
提前致谢。
最佳答案
我会选择另外两张 table :
Client_ThirdParty
Portfolio_ThirdParty
这将充当两个现有表和“第三方”之间的链接实体。我会避开看起来像伪装的元数据的“关系”表。
编辑
For example, Client 1 has Portfolio 1 and Portfolio 2. Client 1 and Portfolio 1 are linked to Promoter 1 but Portfolio 2 is linked to a different Promoter.
Do you mean three additional tables? ThirdParty, Client_Relationship and Portfolio_Relationship? I ask this as both Client and Portfolio relationships are to a single 'pool' of Third Parties.
好的,如果要考虑更多的关系,那么您可能需要更复杂的东西(但由于我不知道您的数据,我可能会遗漏一些东西!):
- 客户可以有很多投资组合
- 客户可以有多个第三方
- 投资组合可以有 1 个客户吗?
- 投资组合可以有很多第三方
- 第三方可以有很多客户
- 第三方可以建立许多投资组合
如果这是正确的,那么:
Client
Portfolio (contains ClientId to refer to its client)
ThirdParty
Client_ThirdParty <-- link entity that handles the Client/ThirdParty M-to-M
Portfolio_ThirdParty <-- link entity that handles the Portfolio/ThirdParty M-to-M
关于sql - 数据库设计 : third table that relates to both parent and child tables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4368159/