我有一个很奇怪的问题。
我有这样的查询,我在 SQL Server 2008 R2 中运行:
SELECT TOP (20) *
FROM MyTable
WHERE a = 0
AND b = 0
AND c = 0
使用我在 MyTable 上的索引
但是这个没有:
SELECT TOP (20) *
FROM MyTable
WHERE a = 0
OR b = 0
OR c = 0
我想在我的程序中执行第二个查询。如何更改第二个查询以使用索引?
索引是:
CREATE NONCLUSTERED INDEX [MyIndex] ON [dbo].[MyTable] (
[a] ASC,
[b] ASC,
[c] ASC
)
WITH (
PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB = OFF,
IGNORE_DUP_KEY = OFF,
DROP_EXISTING = OFF,
ONLINE = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON
) ON [PRIMARY]