Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I've read through several of the oracle tutorials that show temporal validity and time features. However, in the examples I'v read, there is no primary key used in the demo tables.

http://docs.oracle.com/cd/E16655_01/appdev.121/e17620/adfns_design.htm#ADFNS1005 http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/ilm/temporal/temporal.html

Should primary keys be added to these tables? I'm asking because I'm wondering about how one of these temporal tables should be referenced by another table. Can I add a foreign key from one temporal table to another?

If I add a pk/ foreign key realtionship, and then update the referenced in the table with the pk, the table with the fk points to a record that is no longer relevant.... does temporal data break normal primary key - foreign key relationships? And if so, how does this affect performance, do I just use a normal column as the 'foreign key' and select the right one for a referenced time period in a query?

Does anybody know of or have any examples or tutorials handy that show temporal data with normal or pseudo-normal pk / fk usage?

Thanks

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Unfortunately present SQL or its implementations in all RDBMS products does not fully support temporal relations.

Only Teradata and DB2 have some features implementing constraints having time in the two or more of columns.

My example:

SET SCHEMA TEST;

CREATE TABLE PRODUCT (
product_ID INT NOT NULL,
suplier NVARCHAR(50),
PRIMARY KEY (product_ID)
) ;

CREATE TABLE CAMPAIGN (
campaign_ID INT NOT NULL,
product_ID INT NOT NULL,
price DECIMAL,
PRIMARY KEY (campaign_ID)
)
;

ALTER TABLE CAMPAIGN
ADD CONSTRAINT XFK_campaign_productid
FOREIGN KEY (product_ID) REFERENCES PRODUCT (product_id)
ON DELETE NO ACTION;

If you add temporal columns business_startdate and business_enddate and optionally
transaction_starttime and transaction_endtime, you cannot enforce referential integrity anymore.

You might have to implement triggers or stored procedures or application level coding if you want to implement a constraint like this:

CREATE TABLE CAMPAIGN (
campaign_ID INT NOT NULL,
product_ID INT NOT NULL,
business_startdate DATE NOT NULL,
business_enddate DATE NOT NULL,
transaction_starttime TIMESTAMP NOT NULL,
transaction_endtime TIMESTAMP NOT NULL,
price DECIMAL,
PRIMARY KEY (campaign_ID,business_startdate,transaction_starttime)
)
;

For DB2 there exist a temporal primary key constaint in the following syntax:

CREATE TABLE CAMPAIGN (
campaign_ID INT NOT NULL,
product_ID INT NOT NULL,
business_startdate DATE NOT NULL,
business_enddate DATE NOT NULL,
price DECIMAL,
PERIOD BUSINESS_TIME (business_startdate,business_enddate),
PRIMARY KEY (campaign_ID,BUSINESS_TIME WITHOUT OVERLAPS)
)
;

share|improve this answer
    
Can you provide a link on features implementing constraints having time in the two or more of columns? –  A-K Dec 23 '13 at 22:13
    
@AlexKuznetsov here is link ibm.com/developerworks/data/library/techarticle/… –  Analyst Dec 29 '13 at 18:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.