Chapter 5. Temporal data management and analytics in an operational warehouse 211
values('Melissa Smith', 'Customer Loyalty Club', 100, '2011-11-01',
'9999-12-30');
Inserting and managing multiple time periods
To be really useful, the application-period temporal table can manage multiple
rows for the same customer covering different time periods. This allows us, for
example, to maintain a history for each customer of which plans they participated
in and for what time periods. Having this information available in our data
warehouse allows us to perform important analysis of the impact of these plans
on both the cost and benefit sides of the equation to determine the effectiveness
of the plans at driving increased revenue and retaining good customers.
Simple inserts into application-period temporal tables
The simplest form of INSERT is for the user or the application to provide the
records and dates for each time period to be captured. For example, here we add
a new customer named Jane Doe. Jane became a customer effective May 20,
2012 but did not immediately join a loyalty program. Starting July 1, 2012, she
enrolled in the basic loyalty program. To insert the full history into our
CUST_LOYALTY table using SQL INSERT, we use the statements in
Example 5-18.
Example 5-18 INSERT for multiple periods for the same customer without overlap
insert into cstinsight.cust_loyalty
values('Jane Doe', 'No Loyalty Scheme', 0, '2012-05-20', '2012-07-01');
insert into cstinsight.cust_loyalty
values('Jane Doe', 'Customer Loyalty Club', 100, '2012-07-01',
'9999-12-30');
If we then look at the table contents as shown in Figure 5-32, we can clearly see
the history of Jane Doe’s involvement in the loyalty program.
Figure 5-32 CUST_LOYALTY table after inserting multiple rows for Jane Doe
Note the end date of her first record is July 1, 2012”, and the start date of her
second record is also July 1, 2012. Keep in mind the discussion from the