1

如何在 MS-SQL 中对索引视图进行分区?我创建了一个存储值范围的索引视图。视图定义如下

CREATE VIEW dbo.target_individual_product WITH SCHEMABINDIN       
    AS SELECT day_dim.date_time AS Date,  
    SUM(ISNULL(order_dim.quantity,0)) AS Target_Acheived,  
    branch_dim.branch_name AS Branch_Name ,   
    product_dim.product_name AS Product_Name  
FROM dbo.day_dim INNER JOIN  
     dbo.order_fact ON day_dim.day_id = order_fact.day_id  
INNER JOIN dbo.product_dim ON order_fact.product_id = product_dim.product_id   
INNER JOIN dbo.branch_dim ON order_fact.branch_id = branch_dim.branch_id   
INNER JOIN dbo.order_dim ON order_fact.order_id = order_dim.order_id  
GROUP BY order_dim.quantity, day_dim.date_time,branch_dim.branch_name, product_dim.product_name  
GO
CREATE UNIQUE CLUSTERED INDEX target_individual_product_I on target_individual_product (Date)

现在我想使用日期列对该表进行分区。我怎么做 ?

4

2 回答 2

2

我对分区几乎没有经验,但我认为你让事情变得混乱。(大师,如果我错了,请纠正我)。

据我所知,SQL Server 中有三种类型的分区

分区表可以按日期等列进行分区。

分区视图是指定UNION来自不同表的相似查询之间的视图。

分区对齐索引视图是一个索引视图,它沿着与其链接的分区表相同的列进行分区。

I don't think it is possible to partition an indexed view without partitioning the underlying table. Therefore, I would suggest that you partition your day_dim on the date_time column, and then create a partition-aligned indexed view to match this column. See this link and scroll down to Query 11 for an example how to do this.

于 2010-11-17T10:57:58.103 回答
1

您似乎正在寻找“分区对齐”索引;SQL 2008 Enterprise Edition 支持分区(您没有提及您的版本或版本)。分区索引在联机丛书中进行了讨论,但我可以找到没有关于分区视图索引的讨论,尽管它是可能的,并且在此处的白皮书中进行了描述(请参阅本文末尾的查询 11):

http://msdn.microsoft.com/en-us/library/dd171921.aspx

于 2010-11-17T10:57:48.660 回答