6. 66
Questions
▪ How to retrieve history data?
▪ What happen if you delete data by accident?
▪ What if I need to retrieve the data in the past, or insert a reserved data for
future use?
→ We need something like time period to attach to the data, this is temporal
data.
A temporal database is a database with built-in support for handling data
involving time.
7. 77
Temporal database
▪ Time period is attached to the data (time varying data).
▪ Express when the data is valid or stored in the database.
▪ Divided into two approaches:
▪ Time period when the data is true in the real world (valid time).
▪ Time period when data is stored in database (transaction time).
9. 99
Valid time approach
ID Name Price Valid From Valid Till
2 Honey 250 01/01/2016 01/09/2017
2 Honey 220 01/09/2017 02/02/2020
2 Honey 300 03/03/2025 04/04/2050
2 Honey 500 06/09/3000 09/06/3005
10. 1010
Valid time approach
▪ Records the time when a fact is true in the real world.
▪ Represents data in the past, current for future
▪ Enables queries that show the state of the fact at a given time.
11. 1111
Transaction time approach
ID Name Price
Valid
From
Valid Till
Known
From
Known
Till
2 Honey 250 01/01/2016 01/09/2017 08/08/2017 31/12/9999
2 Honey 220 01/09/2017 02/02/2020 08/08/2017 31/12/9999
2 Honey 300 03/03/2025 04/04/2050 08/08/2017 31/12/9999
2 Honey 500 06/09/3000 09/06/3005 08/08/2017 08/11/2017
2 Honey 5000 06/09/3000 09/06/3005 08/11/2017 31/12/9999
12. 1212
Transaction time approach
▪ Records the time period during which a database entry is accepted as
correct.
▪ Enables queries that show the state of the database at a given time.
▪ Only occur in the past or up to the current time.
▪ In a transaction time table, records are never deleted.
16. 1616
Bi-Temporality
▪ In bi-temporality, we take care both point of view the validity and point of
view of the change.
▪ Through them, we get the exact valid information of the system at specific
time.
▪ No physical delete of the row in database.
17. 1717
Use cases
▪ You want to reprint of a customer’s invoices of July 2017.
▪ What was the profit last year?
▪ Where do you enter the new address of this customer since the first next
month?
▪ The client wants to book a reservation of your hotel next year.
18. 1818
Application domains
▪ Financial apps: portfolio management, accounting, banking.
▪ Record-keeping: personal, medical, inventory management.
▪ Scheduling apps: airline, train, hotel reservation...
▪ CRM apps (customer history / future)
⇒ Time varying data has always been in business requirements.
24. 2424
Insert
Action Data Valid From Valid Till Known From Known Till
Insert A 01.01.2016 31.12.9999 sysdate 31.12.9999
▪ 01.01.2016: when the data is valid
▪ 31.12.9999: infinity
▪ sysdate: “now”
36. 3636
Update future with infinity
Action Data Valid From Valid Till Known From Known Till
Update A - - - sysdate
Insert A 01.01.2016 06.06.2016 sysdate 31.12.9999
Insert B 06.06.2016 31.12.9999 sysdate 31.12.9999
37. 3737
Update the past with infinity
Update record by value “C”, effect from 03.03.2016.
38. 3838
Update the past with infinity
sysdate1
Valid
Know
01.01.2016
A
A
sysdate2
06.06.2016
B
39. 3939
Update the past with infinity
sysdate1
Valid
Know
01.01.2016
A
A
sysdate2
06.06.2016
B
sysdate3
C
03.03.2016
40. 4040
Update the past with infinity
Action Data Valid From Valid Till Known From Known Till
Update A - - - sysdate
Update B - - - sysdate
Insert A 01.01.2016 03.03.2016 sysdate 31.12.9999
Insert C 03.03.2016 31.12.9999 sysdate 31.12.9999
41. 4141
Update the past with close date after first update
Update record by value “C”, effect from 03.03.2016 to 09.09.2016.
42. 4242
Update the past with close date after first update
sysdate1
Valid
Know
01.01.2016
A
A
sysdate2
06.06.2016
B
43. 4343
Update the past with close date after first update
sysdate1
Valid
Know
01.01.2016
A
A
sysdate2
06.06.2016
B
sysdate3
C
03.03.2016 09.09.2016
B
44. 4444
Update the past with close date after first update
Action Data Valid From Valid Till Known From Known Till
Update A - - - sysdate
Update B - - - sysdate
Insert C 03.03.2016 09.09.2016 sysdate 31.12.9999
Insert A 01.01.2016 03.03.2016 sysdate 31.12.9999
Insert B 09.09.2016 31.12.9999 sysdate 31.12.9999
45. 4545
Update the past with close date before first update
Update record by value “C”, effect from 03.03.2016 to 04.04.2016
46. 4646
Update the past with close date before first update
sysdate1
Valid
Know
01.01.2016
A
A
sysdate2
06.06.2016
B
47. 4747
Update the past with close date before first update
sysdate1
Valid
Know
01.01.2016
A
A
sysdate2
06.06.2016
B
sysdate3
C
03.03.2016 09.09.2016
A A
04.04.2016
48. 4848
Update the past with close date before first update
Action Data Valid From Valid Till Known From Known Till
Update A - - - sysdate
Keep B - - - -
Insert C 03.03.2016 04.04.2016 sysdate 31.12.9999
Insert A 01.01.2016 03.03.2016 sysdate 31.12.9999
Insert A 04.04.2016 06.06.2016 sysdate 31.12.9999
49. 4949
When to use
Ask yourself two questions:
▪ Does your business need to know the situation as it was known at a particular
date?
▪ Does your business use information that was effective in the past or will become
effective in the future?
⇒ If you answer YES on one or both of these question then your data varies
over time and you could consider adopting a temporal approach.