Deleting data from a bitemporal table
Deleting data from a bitemporal table results in rows that are deleted from the table, rows that are added to its associated history table and can potentially result in new rows that are inserted into the bitemporal table itself.
About this task
Procedure
To delete data from a bitemporal table, use the DELETE
FROM statement.
For example, it was discovered that
policy A123 did not have coverage from June 15, 2008 to August 15,
2008. The data was deleted on September 1, 2011 (2011-09-01) from
the table that was updated in the
Updating data in a bitemporal tabletopic.
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 and hist_policy_info table
data is as follows:
| policy_id | coverage | bus_start | bus_end | sys_start | sys_end | ts_id |
|---|---|---|---|---|---|---|
| A123 | 12000 | 2008-01-01 | 2008-06-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| A123 | 14000 | 2008-06-01 | 2008-07-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| A123 | 14000 | 2008-07-01 | 2008-08-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| A123 | 16000 | 2008-08-01 | 2009-01-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| B345 | 18000 | 2008-03-01 | 2009-01-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| C567 | 25000 | 2008-01-01 | 2009-01-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| policy_id | coverage | bus_start | bus_end | sys_start | sys_end | ts_id |
|---|---|---|---|---|---|---|
| A123 | 12000 | 2008-01-01 | 2008-07-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| A123 | 16000 | 2008-07-01 | 2009-01-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| B345 | 18000 | 2008-01-01 | 2009-01-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| C567 | 20000 | 2008-01-01 | 2009-01-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
policy_info table
for policy_id A123 that include all or part of that
time period.As a result, the following things 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_startvalue of 2008-07-01 and abus_endvalue of 2008-08-01 is deleted. - When only the
bus_endvalue 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_endvalue is set to 2008-06-15. Thesys_start,sys_end, andts_idcolumn entries are generated by the database manager. - When only the
bus_startvalue 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_startvalue is set to 2008-08-15. Thesys_start,sys_end, andts_idcolumn entries are generated by the database manager. - The original rows are moved to the history table. The database
manager updates the
sys_endvalue to the date of the delete.
| policy_id | coverage | bus_start | bus_end | sys_start | sys_end | ts_id |
|---|---|---|---|---|---|---|
| A123 | 12000 | 2008-01-01 | 2008-06-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| A123 | 14000 | 2008-06-01 | 2008-06-15 | 2011-09-01- 12.18.22. 959254000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-09-01- 12.18.22. 959254000000 |
| A123 | 16000 | 2008-08-15 | 2009-01-01 | 2011-09-01- 12.18.22. 959254000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-09-01- 12.18.22. 959254000000 |
| B345 | 18000 | 2008-03-01 | 2009-01-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| C567 | 25000 | 2008-01-01 | 2009-01-01 | 2011-02-28- 09.10.12. 649592000000 |
9999-12-30- 00.00.00. 000000000000 |
2011-02-28- 09.10.12. 649592000000 |
| policy_id | coverage | bus_start | bus_end | sys_start | sys_end | ts_id |
|---|---|---|---|---|---|---|
| A123 | 12000 | 2008-01-01 | 2008-07-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| A123 | 16000 | 2008-07-01 | 2009-01-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| B345 | 18000 | 2008-01-01 | 2009-01-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| C567 | 20000 | 2008-01-01 | 2009-01-01 | 2010-01-31- 22.31.33. 495925000000 |
2011-02-28- 09.10.12. 649592000000 |
2010-01-31- 22.31.33. 495925000000 |
| A123 | 14000 | 2008-06-01 | 2008-07-01 | 2011-02-28- 09.10.12. 649592000000 |
2011-09-01- 12.18.22. 959254000000 |
2011-09-01- 12.18.22. 959254000000 |
| A123 | 14000 | 2008-07-01 | 2008-08-01 | 2011-02-28- 09.10.12. 649592000000 |
2011-09-01- 12.18.22. 959254000000 |
2011-09-01- 12.18.22. 959254000000 |
| A123 | 16000 | 2008-08-01 | 2009-01-01 | 2011-02-28- 09.10.12 .649592000000 |
2011-09-01- 12.18.22. 959254000000 |
2011-09-01- 12.18.22. 959254000000 |