Is there any need to add an index to a foreign key in SQL Server 2008 or is this handled by default. In many of my tables I have one FK that points to the user account table and most selects are made with this WHERE Account_FK = id. So index could be a quick performance win here i hope.
Is there any need to add an index to a foreign key in SQL
Share
As a rule, you want all your
JOINkeys to have indexes on them, so yes add an index.If it’s a composite key make sure to put all the relevant fields in the index key list in an appropriate order.
To my knowledge the only times an index is created automatically in SQL Server is when you add a primary key to a heap (non-indexed table) – the PK is assigned as the Clustered Index Key automatically; or, as Damien points out below, when you add a
UNIQUEconstraint to a field or set of fields.