seeking Indexing advise, SQL Server 2012 Express

I have ParentTable with 14,000 rows with PK on ID char(7) which already has clustered index.

The next table (ChildTable with 1,500,000 rows) has FK on ID char(7).

Question 1: Do I need to index this FK? This FK is not unique.

There is another field I will searching called Field1 also  not unique.

Question 2: Is the following lines of code correct to build these two indexes?

CREATE INDEX index_FK_ID_ChildTable ON ChildTable (ID);    
CREATE INDEX index_Field1_ChildTable ON ChildTable (Field1);  

Question 3:Once these indexes get build, are created automatically? How long it might take. Any other pitfalls are there I need to be aware of?
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Question 1: Do I need to index this FK? This FK is not unique
Yes you need. It's always a best practice to index the FK's since they will be used in JOIN clauses. The part of being not unique is irrelevant.

Question 2: Is the following lines of code correct to build these two indexes?
Yes.

Question 3:Once these indexes get build, are created automatically? How long it might take. Any other pitfalls are there I need to be aware of?
They are build in the moment you press the execute button and the time depends only on the number of records that the table has. Be aware that this operation will create locks so execute it during maintenance hours. And since index gets fragmented you need to have reindex and rebuild tasks in your maintenance plan.
0
 
HuaMin ChenSystem AnalystCommented:
You can have index on non-unique, but be aware of not having index on column having many many repeating values.

The speed would be quick to build indices to the table.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.