Primary Key and Unique Constraints for ANSI Bitemporal Tables | Teradata Vantage - Primary Key and Unique Constraints for ANSI Bitemporal Tables - Analytics Database - Teradata Vantage

ANSI Temporal Table Support

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-10-30
dita:mapPath
jqu1628112571823.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esa1472244798285
lifecycle
latest
Product Category
Teradata Vantageā„¢

Like valid-time table definitions, bitemporal table definitions can include primary key and unique constraints that prevent rows from having valid-time periods that overlap.

Syntax

The syntax for adding a primary key or unique constraint to bitemporal tables is the same as the syntax used for valid-time tables, described in Primary Key and Unique Constraints for ANSI Valid-Time Tables.

Usage Notes

  • The system-time derived period column cannot be included in the columns that constitute the primary key or unique constraint.
  • The constraint applies only to rows that are open in the system-time dimension.

Example: Temporal Primary Key Constraint on an ANSI Bitemporal Table

CREATE MULTISET TABLE employee_bitemp_pk (
 eid INTEGER NOT NULL,
 ename VARCHAR(5) NOT NULL,
 deptno INTEGER NOT NULL,
 terms VARCHAR(5),
 job_start DATE NOT NULL,
 job_end DATE NOT NULL,
 PERIOD FOR job_dur(job_start,job_end) AS VALIDTIME,
 sys_start TIMESTAMP(6) WITH TIME ZONE NOT NULL 
           GENERATED ALWAYS AS ROW START,
 sys_end TIMESTAMP(6) WITH TIME ZONE NOT NULL 
           GENERATED ALWAYS AS ROW END,
 PERIOD FOR SYSTEM_TIME(sys_start,sys_end)
 PRIMARY KEY(deptno,job_dur WITHOUT OVERLAPS)
 )
 PRIMARY INDEX (eid) WITH SYSTEM VERSIONING;