0

我正在试图找出我的事实表(它们都有类似的结构)的聚集索引使用什么字段。我将使用FactSales作为一个例子与许多网站的事实表上的群集索引

CREATE TABLE dbo.FactSales 
(
DateOfSaleKey int NOT NULL, -- PK, 
--ProfitCentreKey int NOT NULL, -- (maybe add this?) 
RevenueCentreKey int NOT NULL, -- PK 
TransactionHeaderNumber int NOT NULL, -- PK 
TransactionDetailNumber int NOT NULL, -- PK 
TableNumber int NOT NULL, 
TransactionOrCheckNumber int NOT NULL, 
TerminalKey int NOT NULL, 
CashierKey int NOT NULL, 
TimeSlotKey int NOT NULL, 
TransactionTypeKey int NOT NULL, 
TransactionDetailTypeKey int NOT NULL, 
MediaKey int NOT NULL, 
SaleItemKey int NOT NULL, 
SaleTypeKey int NOT NULL, 
SalesQuantity int NOT NULL, 
SalesGross smallmoney NOT NULL, 
SalesNet decimal (16, 8) NOT NULL, 
VAT decimal (16, 8) NOT NULL, 
... 
) 

加载: 事实表由ProfitCentre(ProfitCentreKey),这是一个单一餐厅加载,并通过天(DateOfSaleKey)。我们在表格中没有ProfitCentreKey,因为我们有更详细的RevenueCentreKey,这是餐厅内的部分。

所以,每个负载看起来是这样的:

DELETE s 
FROM FactSales s 
INNER JOIN DimOrganisation o ON s.RevenueCentreKey = o.RevenueCentreKey 
WHERE s.DateOfSaleKey = 20160105 AND o.ProfitCentreKey = 385 

INSERT INTO FactSales (DateOfSaleKey, RevenueCentreKey, ...) 
SELECT DateOfSaleKey, RevenueCentreKey, ... FROM #SalesForProfitCentreAndDateOfSale 

什么我考虑...

(1)聚集索引:DateOfSaleKey。 这可能会使INSERT更容易,但我不确定DELETE。

(2)聚集索引:DateOfSaleKey,ProfitCentreKey。 我将不得不将ProfitCentreKey添加到表中。这可能使删除更容易,但它会碎裂表作为ProfitCentreKey不会加载顺序

和删除将simplier:

DELETE FROM FactSales WHERE DateOfSaleKey = 20160105 AND ProfitCentreKey = 385 

任何建议,将真正帮助。谢谢

回答

0

嗨如果只关心是删除。

您应该使用分区表。 在ProfitCentreKey上创建分区功能。 然后切换部分。