Are foreign keys indexed automatically in SQL Server?

前端 未结 3 455
忘了有多久
忘了有多久 2020-12-08 00:18

Would the following SQL statement automatically create an index on Table1.Table1Column, or must one be explicitly created?

Database engine is SQL Server 2000

3条回答
  •  无人及你
    2020-12-08 00:19

    SQL Server will not automatically create an index on a foreign key. Also from MSDN:

    A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table. A FOREIGN KEY constraint can contain null values; however, if any column of a composite FOREIGN KEY constraint contains null values, verification of all values that make up the FOREIGN KEY constraint is skipped. To make sure that all values of a composite FOREIGN KEY constraint are verified, specify NOT NULL on all the participating columns.

提交回复
热议问题