Chapter 5. Temporal data management and analytics in an operational warehouse 227
settings that facilitate running existing applications and simplify new application
programming.
Using these new register settings can allow existing queries to gain maximum
benefit from temporal features without having to be modified with the appropriate
FOR SYSTEM_TIME or FOR BUSINESS_TIME clauses. The “CURRENT” time
can be set and applied to all queries against system-period or application-period
tables that do not otherwise include a FOR SYSTEM_TIME or FOR
BUSINESS_TIME clause.
The statement in Example 5-34 sets the SYSTEM_TIME register to one week
prior to the current time stamp.
Example 5-34 Set the current system time to offset of current time
SET CURRENT TEMPORAL SYSTEM_TIME = CURRENT TIMESTAMP - 1 WEEK;
After this statement, all queries against system-period temporal tables that do
not have explicit FOR SYSTEM_TIME clauses have this clause applied implicitly:
FOR SYSTEM_TIME AS OF CURRENT TIMESTAMP - 1 WEEK
The statement in Example 5-35 sets the BUSINESS_TIME register to the literal
date value for March 1, 2012.
Example 5-35 Set the current business time to a date literal
SET CURRENT TEMPORAL BUSINESS_TIME = ‘2012-03-01’;
After this statement, all queries against application-period temporal tables that do
not have explicit FOR BUSINESS_TIME clauses have this clause applied
implicitly:
FOR BUSINESS_TIME AS OF ‘2012-03-01’
Avoid having two time constraints applied simultaneously: Similar to the
restriction on views, it is critical to avoid having two time constraints applied to
the same query simultaneously.
You cannot:
Set the special SYSTEM_TIME register and use the FOR SYSTEM_TIME
AS OF clause in a SQL query.
Set the special BUSINESS_TIME register and use the FOR
BUSINESS_TIME AS OF clause in a SQL query.
You must use one approach or the other, but never both at the same time.