Should every SQL Server foreign key have a matching index?

前端 未结 4 988
粉色の甜心
粉色の甜心 2020-12-04 16:10

Is it good practice to create an index for every foreign key in a SQL Server database?

4条回答
  •  没有蜡笔的小新
    2020-12-04 16:49

    From MSDN: FOREIGN KEY Constraints

    Creating an index on a foreign key is often useful for the following reasons:

    • Changes to PRIMARY KEY constraints are checked with FOREIGN KEY constraints in related tables.
    • Foreign key columns are frequently used in join criteria when the data from related tables is combined in queries by matching the column or columns in the FOREIGN KEY constraint of one table with the primary or unique key column or columns in the other table.

提交回复
热议问题