Creating a bitemporal table
Creating a bitemporal table results in a table that combines the historical tracking of a system-period temporal table with the time-specific data storage capabilities of an application-period temporal table.
About this task
- Include both a SYSTEM_TIME period and a BUSINESS_TIME period in the CREATE TABLE statement.
- Create a history table to receive old rows from the bitemporal table.
- Add versioning to establish the link between the bitemporal table and the history table.
- Optionally, define that overlapping periods of BUSINESS_TIME are not allowed and that values are unique with respect to any period.
Procedure
To create a bitemporal table:
Results
policy_info
table stores the insurance
coverage level for a customer. The BUSINESS_TIME period-related columns
(bus_start
and bus_end
) indicate
when an insurance coverage level is valid. The SYSTEM_TIME period-related
columns (sys_start
and sys_end
)
show when a coverage level row is current. The ts_id
column
lists the time when execution started for a transaction that impacted
the row.
policy_id | coverage | bus_start | bus_end | sys_start | sys_end | ts_id |
---|---|---|---|---|---|---|
The
hist_policy_info
history table receives
the old rows from the policy_info
table.
policy_id | coverage | bus_start | bus_end | sys_start | sys_end | ts_id |
---|---|---|---|---|---|---|
The ix_policy
index, with BUSINESS_TIME
WITHOUT OVERLAPS as the final column in the index key column list,
ensures that there are no overlapping time periods for customer insurance
coverage levels.
Example
- Hiding columns
- The following example creates the
policy_info
table with the TIMESTAMP(12) columns (sys_start
,sys_end
andts_id
) marked as implicitly hidden.
Creating theCREATE TABLE policy_info ( policy_id CHAR(4) NOT NULL, coverage INT NOT NULL, bus_start DATE NOT NULL, bus_end DATE NOT NULL, sys_start TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN IMPLICITLY HIDDEN, sys_end TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END IMPLICITLY HIDDEN, ts_id TIMESTAMP(12) GENERATED ALWAYS AS TRANSACTION START ID IMPLICITLY HIDDEN, PERIOD BUSINESS_TIME (bus_start, bus_end), PERIOD SYSTEM_TIME (sys_start, sys_end) ) in policy_space;
hist_policy_info
history table using the LIKE clause of the CREATE TABLE statement results in the history table inheriting the implicitly hidden attribute from thepolicy_info
table.