Why does the primary key matter?

I recently created a class in an EntityFramework project that designated a couple of its members as a composite key.

However, when it came to creating the database, it gave an error

It is not possible to determine the composite order of the primary key for type "NNNNN". Use the ColumnAttribute or the HasKey method to specify the order for composite primary keys.

I know how to solve the problem, but I'm just wondering why she cares about the order. Is not only a set of columns on which records should be recorded without any specific order a composite primary key?

+4
source share
1 answer

This is important because the order of the primary keys matters in the database. Since primary keys are (usually) clustered and always indexes, regardless of whether the key is ordered as first name, last name, SSN or SSN, last name, first name, is of great importance. If I have only SSN when I query the table and PK is the only index, I will see GREAT performance with the latter and a full scan of the table with the previous.

+5
source

Source: https://habr.com/ru/post/1482371/


All Articles