What are the down sides of using a composite/compound primary key?

后端 未结 8 2269
说谎
说谎 2020-12-14 20:30

What are the down sides of using a composite/compound primary key?

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 21:14

    There's nothing wrong with having a compound key per se, but a primary key should ideally be as small as possible (in terms of number of bytes required). If the primary key is long then this will cause non-clustered indexes to be bloated.

    Bear in mind that the order of the columns in the primary key is important. The first column should be as selective as possible i.e. as 'unique' as possible. Searches on the first column will be able to seek, but searches just on the second column will have to scan, unless there is also a non-clustered index on the second column.

提交回复
热议问题