您好我正在尝试将数据导入我的数据仓库并简化一些数据的导入,我想在表中创建一个新列,以便在获取新数据时跟踪最新值。
我的表如下所示:
CREATE TABLE CustomerFact(
Id INT IDENTITY PRIMARY KEY
,CustomerId NVARCHAR(20) NOT NULL --Current Id of a Customer
);
--Track changes to CustomerId
CREATE TABLE CustomerHistoryFact(
Id INT IDENTITY PRIMARY KEY
,CurrentCustomerId NVARCHAR(20) --Most recent Customer Id
,CustomerId NVARCHAR(20) NOT NULL --Customer Id at time of record insert
,PrvsCustomerId NVARCHAR(20) NOT NULL --Customer Id at time of transaction
,PrvsCustomerIdEffectiveDate DATE NOT NULL --Date when PrvsCustomerId was effective
,PrvsCustomerIdObsoleteDate DATE NOT NULL --When the PrvsCustomerId was expired and replaced with a new Customer Id
);
、CustomerId
、PrvsCustomerId
和都是外部的PrvsCustomerIdEffectiveDate
。PrvsCustomerIdObsoleteDate
我想在CurrentCustomerId
插入新记录时分配一个。
这取决于何时插入新记录,CustomerHistoryFact
检查所有其他记录。如果匹配,则新记录的 成为所有先前记录的 ,否则插入记录并成为。PrvsCustomerId
CurrentCustomerId
CustomerId
CurrentCustomerId
CustomerId
CurrentCustomerId