Composite primary key or not?

前端 未结 4 899
野的像风
野的像风 2020-11-28 07:26

Here\'s what\'s confusing me. I often have composite primary keys in database tables. The bad side of that approach is that I have pretty extra work when I delete or edit en

4条回答
  •  温柔的废话
    2020-11-28 07:59

    I know it is a very long time since this post was made. But I had to come across a similar situation regarding the composite key so I am posting my thoughts.

    Let's say we have two tables T1 and T2.

    T1 has the columns C1 and C2.

    T2 has the columns C1, C2 and C3

    C1 and C2 are the composite primary keys for the table T1 and foreign keys for the table T2.

    Let's assume we used a surrogate key for the Table T1 (T1_ID) and used that as a Foreign Key in table T2, if the values of C1 and C2 of the Table T1 changes, it is additional work to enforce the referential ingegrity constraint on the table T2 as we are looking only at the surrogate key from Table T1 whose value didn't change in Table T1. This could be one issue with second approach.

提交回复
热议问题