简体   繁体   English

我的分区视图仍在访问所有底层基表

[英]My partitioned view is still accessing all underlying base tables

I am trying to create a partitioned view, however my execution plan is showing that it is still accessing both underlying tables. 我正在尝试创建一个分区视图,但是我的执行计划显示它仍在访问两个基础表。

SQL Fiddle here SQL小提琴在这里

Why is my query still accessing both underlying tables and then concatenating them? 为什么我的查询仍然访问两个基础表然后连接它们?

Most likely the issue is that your CHECK Constraint does not match your WHERE condition. 最有可能的问题是您的CHECK约束与您的WHERE条件不匹配。

Your Check Constraints are in the form of: 您的检查约束的形式为:

(datepart(year,[StockDate])=(2016))

Your WHERE condition is in the form of: 您的WHERE条件是以下形式:

StockDate = '20160101'

Change your Check Constraints to use full dates (plus there is no need to use a function -- DATEPART -- for such a simple filter). 更改您的检查约束以使用完整日期(此外,不需要使用函数 - DATEPART - 用于这样一个简单的过滤器)。 The following is for the 2016 table: 以下是2016年表:

[StockDate] >= '01/01/2016' AND [StockDate] <= '12/31/2016'

Repeat that for the other tables, changing the year in both predicates to match the year of the table. 对其他表重复此操作,更改两个谓词中的年份以匹配表的年份。

Please note that the syntax above does not state the time component because the field in question is a DATE datatype. 请注意,上面的语法没有说明时间组件,因为有问题的字段是DATE数据类型。 If the datatype were DATETIME , then the end of the range would need to be expressed as: 如果数据类型是DATETIME ,那么范围的结尾将需要表示为:

'12/31/2016 23:59.59.997'

For more info on Partitioned Views, please see the MSDN page for Using Partitioned Views . 有关分区视图的更多信息,请参阅使用分区视图的MSDN页面。

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

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