如何在SQL表中选择索引

时间:2021-02-14 09:17:57

How to choose an index for the SQL Server table?

如何为SQL Server表选择索引?

R (ID, name, salary, zipcode)

ID is the primary key (clustered index)

ID是主键(聚簇索引)

Queries:

select * 
from R 
where salary < 4000 and name = "john"

select * 
from R 
where id = 100 and zipcode = '76200'

select * 
from R 
where salary > 10000

I have an exam tomorrow and since it is paper pen exam I cannot check whether the indices I chose are correct or not. So I am stuck in this question.

我明天参加考试,因为它是纸笔考试我无法检查我选择的索引是否正确。所以我陷入了这个问题。

We need to choose 2 other indices and mention

我们需要选择其他两个指数并提及

  1. which attribute form a search key
  2. 哪个属性构成搜索关键字

  3. index should be clustered or unclustered
  4. index应该是群集的或非群集的

  5. index should be hashed or B+ tree.
  6. 索引应该是哈希或B +树。

Could you please guide me on how to choose the index manually and justify the question above?

您能否指导我如何手动选择索引并证明上述问题的合理性?

Thank you in advance

先谢谢你

1 个解决方案

#1


2  

this is a good reading about that matter that can help you to choose the index manually SQL Server Index Design Guidelines

这是一个很好的阅读,可以帮助您手动选择索引SQL Server索引设计指南

and this SO link talk about clustering key, some point also mentioned in the above link picking a clustering key

并且这个SO链接谈论了聚类密钥,在上面的链接中也提到了一些选择聚类密钥的点

#1


2  

this is a good reading about that matter that can help you to choose the index manually SQL Server Index Design Guidelines

这是一个很好的阅读,可以帮助您手动选择索引SQL Server索引设计指南

and this SO link talk about clustering key, some point also mentioned in the above link picking a clustering key

并且这个SO链接谈论了聚类密钥,在上面的链接中也提到了一些选择聚类密钥的点