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
 General SQL Server Forums
 New to SQL Server Programming
 Separate index or Composite index

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2009-06-22 : 05:33:03
Hi,

I have a table with large amount of data and it has no primary key. I want to create non clustered indexes on two columns.

For eg: assume i have col1, col2, col3, col4 in my table.

Solution 1: Create single nonclustered index on col1 and col2
solution 2: create non clustered index on col1 and col2 separately.

Which one is better solution. Please Suggest..

I think solution 1 is better...Please share ur ideas..

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-22 : 05:39:27
It depends on the nature of queries run against the table.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-06-22 : 05:42:01
quote:
Originally posted by Peso

It depends on the nature of queries run against the table.



E 12°55'05.63"
N 56°04'39.26"




Can you please explain what do you mean in brief???

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-22 : 05:44:38
How is the table used.

How are the JOINs made? How are the WHEREs written?
Are more columns used in the queries?

Maybe you should use the INCLUDE keyword?

CREATE INDEX IX_Peso ON Table1 (Col1, Col2) INCLUDE (Col3, Col4, Col5)


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-06-22 : 08:27:56
thanx for the suggestion...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-22 : 08:53:11
I didn't make a suggestion. I tried to explain that we don't know much about your application nor table and it's data to make any assumption.
The INCLUDE thingy above is just another index strategy available in SQL Server 2005 and later.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -