如何以增量方式加载事实 table?

How to load a fact table incrementally?

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 世界移动到事实 table。我如何通过更改上面介绍的代码或模式来做到这一点?

通常,您可以使用日期字段(如果可以)从以下位置过滤出要进行增量加载(也称为增量加载)的记录:

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)