Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

I have a table with 3 foreign keys in it.

My question was: should I create a single covering index on the 3 FK or I should create 3 separate indexes ?

 

Thanks

  • *Experts*
Posted

It depends on how the index will be used. An index won't get picked unless the first column(s) are used in a query. Suppose you put columns A, B and C in an index like so:

CREATE INDEX idxTest ON TestTable(A, B, C)

 

A query using column B or C (or both) will not use this index. Indexes are a tricky business to figure out. If the table does not get a lot of INSERTs, then you could consider adding multiple indexes (one on each column) and one or more multi-column indexes if needed.

 

Now, if you always join to this table on all 3 columns, then it would help to put all 3 in the index.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...