database design - Composite Index vs. INCLUDE Covering Index in SQL Server -


i understand composite indexes used left right (e.g. if index on city, state, city = "blah" or city = "blah" , state = "aa" work fine state = "aa" not).

does same principle apply include indexes?

thanks in advance!

clay

include columns can used supply columns select portion of query. cannot used part of index filtering.

edit: further clarify point, consider example:

i create simple table , populate it:

create table mytest (     id int,     name char(10) )  insert mytest     (id, name)     select 1, 'joe' union     select 2, 'alex' 

now consider these 3 indexes , corresponding execution plans simple select.

select id, name     mytest     name = 'joe' 

case 1: index on id results in table scan.

create index idx_mytest on mytest(id) 

alt text

case 2: index on id including name. better because index covers query, still scan operation.

create index idx_mytest on mytest(id) include (name) 

alt text

case 3: index on name including id. best. index built on column in clause, seek operation, , index covers query because of included column.

create index idx_mytest on mytest(name) include (id) 

alt text


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -