Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / January 2006

Tip: Looking for answers? Try searching our database.

Impossible Relationship? Referential Integrity on tables with on From Date and To Date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HGT - 11 Jan 2006 17:56 GMT
Hello all,

I am currently on a project which the source data come into the
databases is always dirty (not surprisingly); however, due to the
design of the database, it is very difficult to impose referential
integrity (esp. Foreign Keys) on these tables. Am I just not thinking
straight? This solution is implemented on multi RDBMS.

Example, we have 2 tables, one with a number of columns and a TIMEID
column to specify the load date (in YYYYMM), on the table, there is a
number of other columns which are IDs and has to refer to other tables.
One example would be currency (CURRENCYID) and it refers the CURRENCY
table. To ensure we capture history on these tables, we make use of a
from date and a to date (FROMDATE and TODATE) on these tables. As the
currency list updates very infrequently, the FROMDATE is represented in
YYYYMM and TOTIME is NULL if it is the most current record.

One problem is that when we try to form a foreign key relationship, as
the column names are not the same and it is not an equality
relationship. The only solution is to implement triggers on the
database. As this is cross database solution - triggers would not be
the easiest way to do it. Did we design it all wrong? I am sure someone
must have seen this problem before.

Many thanks in advance.

Regards,
HGT
Knut Stolze - 11 Jan 2006 18:51 GMT
> Hello all,
>
[quoted text clipped - 19 lines]
> the easiest way to do it. Did we design it all wrong? I am sure someone
> must have seen this problem before.

I don't know if I got this right... Do you want to have this:

(1) One table T ( TIMEID, DATE_VALUE )
(2) Another table C ( CURRENCYID, FROMDATE, TODATE )

Where C(FROMDATE) and C(TODATE) both refer to T(DATE_VALUE) (or T(TIMEID)).
Or is it the other way around and you want to establish an integrity
constraint that says that your DATE_VALUE must be somewhere in the interval
defined by [FROMDATE, TODATE]?

The first case will simply work, assuming a proper definition of the data
types.  The second case with the ranges will not work as referential
constraints always test for equality and not for BETWEEN.  Triggers would
be a way to solve the issue.

Signature

Knut Stolze
DB2 Information Integration Development
IBM Germany

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.