Composite primary key

前端 未结 8 1561
旧巷少年郎
旧巷少年郎 2020-12-15 18:37

I am working on the design of a database that will be used to store data that originates from a number of different sources. The instances I am storing are assigned unique I

8条回答
  •  渐次进展
    2020-12-15 19:12

    You have a business requirement that the combination of those two attributes are unique. So, you should have a UNIQUE constraint on those two attributes. Whether you call that UNIQUE constraint "primary" is really just a preference, it doesn't have much impact aside from documentation.

    The only question is whether you then add an extra column and mark it UNIQUE. The only reason I can see to do that is performance, which is a legitimate reason.

    Personally, I don't like the approach of turning every database into essentially a graph, where the generated columns are essentially pointers and you are just traversing from one to the next. I think that throws away all of the greatness of a relational system. If you step back and think about it, you're introducing a bunch of columns that have no meaning to your business, at all. You may be interested in my related blog post.

提交回复
热议问题