Index Key Column VS Index Included Column

前端 未结 5 710
迷失自我
迷失自我 2021-01-30 12:42

Can someone explain this two - Index Key Column VS Index Included Column?

Currently, I have an index that has 4 Index Key Column and 0 Included Column.

Thanks

5条回答
  •  广开言路
    2021-01-30 13:15

    Included columns dont form part of the key for the index, but they do exist on the index. Essentially the values will be duplicated Below Take two type of indexes with example column

    CREATE clustered INDEX NC_index1 ON tableName (column1, column1, column1,column4)
    CREATE clustered INDEX NC_index2 ON tableName (column1) INCLUDE (column2, column3,column4)
    

    NC_index1 is better suited for this kind of query:

    SELECT * FROM tableName WHERE column1 = x AND column1 = y AND column1 = z and column4=n
    

    Whereas NC_index2 is better suited for this kind of query:

    SELECT column1, column2 FROM tableName WHERE column1 = a
    

    because sql server can't allowed to create index on datatype (eg, XML,text, etc)

提交回复
热议问题