http://technet.microsoft.com/zh-cn/library/ms189788(v=SQL.110).aspx
CHECKSUM 用于生成哈希索引。
通过将计算校验和列添加到索引的表中,然后对校验和列生成索引来生成哈希索引。
-- Create a checksum index. SET ARITHABORT ON; USE AdventureWorks2012; GO ALTER TABLE Production.Product ADD cs_Pname AS CHECKSUM(Name); GO CREATE INDEX Pname_index ON Production.Product (cs_Pname); GO
校验和索引可用于等价搜索。
/*Use the index in a SELECT query. Add a second search condition to catch stray cases where checksums match, but the values are not the same.*/ SELECT * FROM Production.Product WHERE CHECKSUM(N'Bearing Ball') = cs_Pname AND Name = N'Bearing Ball'; GO
然而,如果键值较长,则很可能不执行校验和索引甚至常规索引。