0

Consider the following scenario:

ParrentLookupTable:

  • PK: SomeCode CHAR(10)
  • has only 5 rows.
  • Does not change often

MyTable:

  • One million rows are being added daily.
  • Has the column SomeCode FK to ParrentLookupTable
  • There is no query that search or sort based on SomeCode

Here is the FK definition

ALTER TABLE MyTable  CONSTRAINT FK_MyTable_ParrentLookupTable_SomeCode FOREIGN KEY(SomeCode)
REFERENCES ParrentLookupTable (SomeCode)

Should I create an index IX_MyTable_SomeCode?

The index would cost IO during this write intensive workload scenario and I am not sure how it becomes useful?

Allan Xu
  • 7,998
  • 11
  • 51
  • 122

1 Answers1

1

In general adding an index on the column in the parent table is to speed up the FK check. In this case it might not help at all. ParentLookupTable will fit into one database page so it should not matter much if it is doing a table scan or a index seek.

Adding an index on the FK column on the child table could help in the case of cascading deletes.

Here is a longer article on the subject http://sqlperformance.com/2012/11/t-sql-queries/benefits-indexing-foreign-keys

rjdevereux
  • 1,842
  • 2
  • 21
  • 35