Deleting data from an application-period temporal table
Deleting data from an application-period temporal table removes rows from the table and can potentially result in new rows that are inserted into the application-period temporal table itself.
About this task
Procedure
To delete data from an application-period temporal table,
use the DELETE FROM statement to delete data.
For example,
it was discovered that policy A123 should not provide coverage from
June 15, 2008 to August 15, 2008 and therefore that data should be
deleted from the table that was updated in the Updating data in an application-period temporal table topic.
DELETE FROM policy_info
FOR PORTION OF BUSINESS_TIME FROM '2008-06-15' TO '2008-08-15'
WHERE policy_id = 'A123';
Results
policy_info
table data is as
follows:
policy_id | coverage | bus_start | bus_end |
---|---|---|---|
A123 | 12000 | 2008-01-01 | 2008-06-01 |
A123 | 14000 | 2008-06-01 | 2008-07-01 |
A123 | 14000 | 2008-07-01 | 2008-08-01 |
A123 | 16000 | 2008-08-01 | 2009-01-01 |
B345 | 18000 | 2008-03-01 | 2009-01-01 |
C567 | 25000 | 2008-01-01 | 2009-01-01 |
policy_info
table
for policy_id
A123 that include all or part of that
time period.The update to policy A123 affects the system-period
temporal table and its history table, causing the following the things
to occur:
- There is one row where the BUSINESS_TIME period in the DELETE
FROM statement covers the entire time period for a row. The row with
a
bus_start
value of 2008-07-01 and abus_end
value of 2008-08-01 is deleted. - When only the
bus_end
value falls into the specified period, the row is deleted. A new row is inserted with the original values from the deleted row, except that thebus_end
value is set to 2008-06-15. - When only the
bus_start
value falls into the specified period, the row is deleted. A new row is inserted with the original values from the deleted row, except that thebus_start
value is set to 2008-08-15.
policy_id | coverage | bus_start | bus_end |
---|---|---|---|
A123 | 12000 | 2008-01-01 | 2008-06-01 |
A123 | 14000 | 2008-06-01 | 2008-06-15 |
A123 | 16000 | 2008-08-15 | 2009-01-01 |
B345 | 18000 | 2008-03-01 | 2009-01-01 |
C567 | 25000 | 2008-01-01 | 2009-01-01 |
Example
- Delete targets
- The FOR PORTION OF BUSINESS_TIME clause can be used only when
the target of the delete statement is a table or a view. The following
DELETE statement returns an error:
DELETE FROM (SELECT * FROM policy_info) FOR PORTION OF BUSINESS_TIME FROM '2008-01-01' TO '2008-06-15';