作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建唯一的非聚集索引,它限制特定列的某些记录,我使用 NOT IN 来过滤它,但由于 NOT IN,我收到错误。有什么替代方法吗?
CREATE UNIQUE NONCLUSTERED INDEX
[UN_Student] ON [dbo].[Student]
(
[School_Cd] ASC,
[Class_Id] ASC,
[Enroll_Dt] ASC,
[Email_Id] ASC
)
WHERE ([School_Cd]='EM' AND [Class_Id] NOT IN (1,2,3))
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)
最佳答案
过滤索引不能使用NOT IN
。您可以改用多个 AND
运算符。 Brent Ozar 有一篇非常好的文章 here关于过滤索引允许和不允许的内容。
CREATE UNIQUE NONCLUSTERED INDEX
[UN_Student] ON [dbo].[Student]
(
[School_Cd] ASC,
[Class_Id] ASC,
[Enroll_Dt] ASC,
[Email_Id] ASC
)
WHERE ([School_Cd]='EM' AND [Class_Id] <> 1 AND [Class_Id] <> 2 AND [Class_Id] <> 3)
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)
关于sql-server - 如何在 SQL Server 中使用 NOT IN 创建过滤索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53749057/
我是一名优秀的程序员,十分优秀!