Convert Transaction-Time to System-Versioned Table with INSERT SELECT | Vantage - Method 2: INSERT ... SELECT to New Table When Transaction-Time Column is Derived Period - Advanced SQL Engine - Teradata Database

ANSI Temporal Table Support

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
kit1592007446534.ditamap
dita:ditavalPath
kit1592007446534.ditaval
dita:id
B035-1186
lifecycle
previous
Product Category
Teradata Vantage™
This method:
  • requires that the executor have the NONTEMPORAL privilege in the database, and that the database be enabled to recognize that privilege. For more information on the NONTEMPORAL privilege, see Teradata Vantage™ - Temporal Table Support, B035-1182.
  • cannot be used if the transaction-time table is row partitioned on the beginning or ending bound of the transaction-time.
  1. Note all the constraints on the transaction-time table.
  2. Drop all the constraints from the transaction-time table.
  3. Use NONTEMPORAL ALTER TABLE to drop the existing transaction-time column. Use the WITHOUT DELETE option to preserve the historical closed rows, which would otherwise be deleted automatically when you drop the transaction-time column:
    ALTER TABLE  transaction_time_table_name
      DROP  transaction_time_column WITHOUT DELETE
  4. Use ALTER TABLE to create the SYSTEM_TIME derived period column and to add attributes to the set the sys_start and sys_end columns in the same ALTER TABLE statement:
    ALTER TABLE  new_table_name
      ADD PERIOD FOR SYSTEM_TIME(sys_start,sys_end)
      ADD sys_start TIMESTAMP(6) WITH TIME ZONE NOT NULL
        GENERATED ALWAYS AS ROW START 
 
      ADD sys_end TIMESTAMP(6) WITH TIME ZONE NOT NULL
        GENERATED ALWAYS AS ROW END;
  5. Add system versioning to make the new table an ANSI system-time temporal table:
    ALTER TABLE  new_table_name
      ADD SYSTEM VERSIONING;
  6. Recreate all the constraints that were dropped in step 2. Note that ANSI constraints behave as NONSEQUENCED constraints.