简体   繁体   English

带空格的SQL Server NVARCHAR索引

[英]SQL Server NVARCHAR index with white space

Can anyone tell me why the first query executes a full table scan, while the second uses the index? 谁能告诉我为什么第一个查询执行全表扫描,而第二个查询使用索引?

在此处输入图片说明

The table has a non-unique, non-clustered index on (ContractType, MaterialType). 该表在(ContractType,MaterialType)上具有非唯一,非聚集索引。 The table is denormalized, which is why I'm using nvarchars instead of foreign keys, and I'd like to keep it that way. 该表是非规范化的,这就是为什么我使用nvarchars而不是外键的原因,并且我想保持这种方式。

See here for the answer, as this question is basically a duplicate of it (I just didn't realize it at the time). 看到这里的答案,因为这个问题基本上是它的重复(当时我只是没有意识到)。

Does it make sense to use an index that will have a low cardinality? 使用基数较低的索引是否有意义?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM