Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 When to Index...

Author  Topic 

shannoncruey
Starting Member

1 Post

Posted - 2008-10-10 : 14:21:34
Hi, I just need clarification on an argument we are having. Take a simple table (mybigfattable) with a composite PK, consisting of two columns - ID_A and ID_B.

Now, say the mybigfattable has a zillion rows. If I do this sql:

select * from mybigfattable x
join myothertable y on x.ID_A = y.id

Will it use the PK index or will it table scan?

In this case do I need to create individual indexes for ID_A and ID_B if they are not referenced as a pair?

Many thanks...S

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-10 : 14:23:06
For your example, it will use the PK index. If there are only two columns in the table, then adding an index ID_B would be fine. You do not need to also index ID_A as that's the first column in the PK index and therefore it would be considered a duplicate.

It is very easy to prove this by looking at the execution plan in Management Studio.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -