如何逐步加载事实表?

时间:2015-07-14 18:54:14

标签: sql-server data-warehouse

INSERT INTO Warehouse.dbo.factOrder
(OrderDate, CustomerID, ProductID, OrderAmount)
SELECT o.Date, c.CustomerID, p.ProductID, ISNULL(Amount,0)
FROM Production.dbo.Orders o
INNER JOIN Warehouse.dbo.dimCustomer c
ON o.CustCode = c.CustomerCode
INNER JOIN Warehouse.dbo.dimProduct p
ON o.Code = p.ProductCode;

我想只将新插入或更改的行从OLTP World移动到事实表中。我如何通过更改代码或架构来实现这一点?

1 个答案:

答案 0 :(得分:0)

通常,如果您可以使用日期字段来过滤掉要从中执行增量加载(也称为增量加载)的记录,则可以使用日期字段:

INSERT INTO Warehouse.dbo.factOrder
(OrderDate, CustomerID, ProductID, OrderAmount)
SELECT o.Date, c.CustomerID, p.ProductID, ISNULL(Amount,0)
FROM Production.dbo.Orders o
INNER JOIN Warehouse.dbo.dimCustomer c
ON o.CustCode = c.CustomerCode
  and c.RecordCreatedDate > '2015-07-14'
INNER JOIN Warehouse.dbo.dimProduct p
ON o.Code = p.ProductCode 
  and p.RecordCreatedDate > '2015-07-14'
WHERE o.RecordCreatedDate > '2015-07-14'; 
--change this to match your date column name and whatever date you would like to increment 
--(delta load)