<small id='LMAP9'></small><noframes id='LMAP9'>

  • <tfoot id='LMAP9'></tfoot>

    <i id='LMAP9'><tr id='LMAP9'><dt id='LMAP9'><q id='LMAP9'><span id='LMAP9'><b id='LMAP9'><form id='LMAP9'><ins id='LMAP9'></ins><ul id='LMAP9'></ul><sub id='LMAP9'></sub></form><legend id='LMAP9'></legend><bdo id='LMAP9'><pre id='LMAP9'><center id='LMAP9'></center></pre></bdo></b><th id='LMAP9'></th></span></q></dt></tr></i><div id='LMAP9'><tfoot id='LMAP9'></tfoot><dl id='LMAP9'><fieldset id='LMAP9'></fieldset></dl></div>

      1. <legend id='LMAP9'><style id='LMAP9'><dir id='LMAP9'><q id='LMAP9'></q></dir></style></legend>
          <bdo id='LMAP9'></bdo><ul id='LMAP9'></ul>

        在 SQL Server 中实现多态关联的最佳方法是什么?

        时间:2023-06-25
        <tfoot id='3syLf'></tfoot>

          • <bdo id='3syLf'></bdo><ul id='3syLf'></ul>

              • <small id='3syLf'></small><noframes id='3syLf'>

                1. <i id='3syLf'><tr id='3syLf'><dt id='3syLf'><q id='3syLf'><span id='3syLf'><b id='3syLf'><form id='3syLf'><ins id='3syLf'></ins><ul id='3syLf'></ul><sub id='3syLf'></sub></form><legend id='3syLf'></legend><bdo id='3syLf'><pre id='3syLf'><center id='3syLf'></center></pre></bdo></b><th id='3syLf'></th></span></q></dt></tr></i><div id='3syLf'><tfoot id='3syLf'></tfoot><dl id='3syLf'><fieldset id='3syLf'></fieldset></dl></div>

                    <tbody id='3syLf'></tbody>

                2. <legend id='3syLf'><style id='3syLf'><dir id='3syLf'><q id='3syLf'></q></dir></style></legend>
                  本文介绍了在 SQL Server 中实现多态关联的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有很多实例需要在我的数据库中实现某种多态关联.我总是浪费大量时间重新考虑所有选项.这是我能想到的3个.我希望有 SQL Server 的最佳实践.

                  I have tons of instances where I need to implement some sort of Polymorphic Association in my database. I always waste tons of time thinking through all the options all over again. Here are the 3 I can think of. I'm hoping there is a best practice for SQL Server.

                  这里是多列方法

                  这里是无外键方法

                  这是基表方法

                  推荐答案

                  我用下面的方案解决了类似的问题:

                  I used the following solution to solve a similar problem :

                  基于Many-Many的设计:即使ObjectN和Something之间的关系是1-Many,它也等同于关系表PK修改后的Many-Many关系.

                  Many-Many based design : Even though the relation is a 1-Many between an ObjectN and Something, it is equivalent to a Many-Many relationship with a modification of the PK of the relation table.

                  首先,我在 ObjectN 和Something per Object 之间创建一个关系表,然后我使用Something_ID 列作为PK.

                  First i create a relation table between an ObjectN and Something per Object and then i use the Something_ID column as the PK.

                  这是Something-Object1关系的DDL,对于Object2和Object3也是一样的:

                  This is the DDL of the Something-Object1 relationship which is the same for Object2 and Object3 as well :

                  CREATE TABLE Something
                  (
                      ID INT PRIMARY KEY,
                      .....
                  )
                  
                  CREATE TABLE Object1
                  (
                     ID INT PRIMARY KEY,
                     .....
                  )
                  
                  CREATE TABLE Something_Object1
                  (
                      Something_ID INT PRIMARY KEY,
                      Object1_ID INT NOT NULL,
                      ......
                  
                      FOREIGN KEY (Something_ID) REFERENCES Something(ID),
                      FOREIGN KEY (Object1_ID) REFERENCES Object1(ID)
                  )
                  

                  此票中其他可能选项的更多详细信息和示例multiple-相同业务规则的外键

                  More details and examples of other possible options in this ticket multiple-foreign-keys-for-the-same-business-rule

                  这篇关于在 SQL Server 中实现多态关联的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:运行更高级的查询时,对象关闭时不允许操作 下一篇:使用 MAX 和 GROUP BY 选择所有相应的字段

                  相关文章

                3. <small id='ox47s'></small><noframes id='ox47s'>

                  1. <tfoot id='ox47s'></tfoot>
                      <bdo id='ox47s'></bdo><ul id='ox47s'></ul>
                  2. <legend id='ox47s'><style id='ox47s'><dir id='ox47s'><q id='ox47s'></q></dir></style></legend>

                    1. <i id='ox47s'><tr id='ox47s'><dt id='ox47s'><q id='ox47s'><span id='ox47s'><b id='ox47s'><form id='ox47s'><ins id='ox47s'></ins><ul id='ox47s'></ul><sub id='ox47s'></sub></form><legend id='ox47s'></legend><bdo id='ox47s'><pre id='ox47s'><center id='ox47s'></center></pre></bdo></b><th id='ox47s'></th></span></q></dt></tr></i><div id='ox47s'><tfoot id='ox47s'></tfoot><dl id='ox47s'><fieldset id='ox47s'></fieldset></dl></div>