【发布时间】:2013-04-16 04:41:09
【问题描述】:
这是自学题,不在现场环境中。
我一直在查询以 A 结尾的名称,所以我想我会在这些数据上创建一个过滤索引,所以它会寻找或扫描。
但它给了我错误。
--Usual Query
SELECT c.contactname
FROM sales.Customers c where c.contactname like '%A'
--1st Tried failed
create NONCLUSTERED INDEX UCI_NameLikeA
on sales.customers(contactname)
where right(contactname,1)='A'
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'LIKE'
--2nd method tried failed
create NONCLUSTERED INDEX UCI_NameLikeA
on sales.customers(contactname)
where right(contactname,1)='A'
Msg 10735, Level 15, State 1, Line 3
Incorrect WHERE clause for filtered index 'UCI_NameLikeA' on table 'sales.customers'.
为什么过滤器索引中不允许使用 Like 和 RIGHT 函数?有什么其他方法可以代替扫描吗?
【问题讨论】:
-
您可以使用
where c.contactname like '%A'创建索引视图,因为过滤后的索引非常有限。然后从中选择with(noexpand)
标签: sql sql-server sql-server-2008 indexing