| Author |
Topic |
|
sixsigma1978
Starting Member
25 Posts |
Posted - 2012-02-02 : 16:05:14
|
| Had a question about how would the database handle this scenario:IF I created a non-clustered index like this (pseudo code): create non clustered index (col1, col2)vs create non clustered index (col1) create non clustered index (col2)Would this be covering the query in both cases? what happens during query execution plan in both cases? select col1, col2 from target_tableAny pointers would help! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sixsigma1978
Starting Member
25 Posts |
Posted - 2012-02-02 : 16:31:08
|
| well - had simply using pseudos - but you can take this:select col1, col2 from target_table where col1 > 12.5I wanted to know whether both of these would qualify as "covered"? create non clustered index (col1, col2)vscreate non clustered index (col1)create non clustered index (col2 |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
|
|
sixsigma1978
Starting Member
25 Posts |
Posted - 2012-02-02 : 21:17:11
|
quote: Originally posted by tkizer Both of THESE would be covering:create non clustered index (col1, col2)create non clustered index (col1) include (col2)SQL will NOT use the index only on col2 for this query. If it uses the one with only col1, it will have to do a lookup on the clustered index to get the col2 info.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Thanks - so having two separate clustered index on columns won't cover the query i specified. It has to be a composite index! Thanks! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sixsigma1978
Starting Member
25 Posts |
Posted - 2012-02-03 : 09:46:25
|
quote: Originally posted by tkizer A table can only have one clustered index. In your example query, only one index can be used. It does not have to be a composite index. Maybe you should read Gail's link.Tara Kizer
my bad - typo - I meant two non clustered indexes!! |
 |
|
|
|