473,385 Members | 1,292 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

HGT
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

Jan 11 '06 #1
1 1920
HGT wrote:
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.


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.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jan 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sharon Cowling | last post by:
Hi, my problem is this: I have a table called faps_key the unique identifier being key_code: taupo=# \d faps_key Table "faps_key" Column | Type | Modifiers...
2
by: Larry R Harrison Jr | last post by:
I have an Access 97 database with 2 tables that have a one-many relationship. I have a SQL statement in the "one" table which I want to execute and insert 7 records into the "many" table, and I...
4
by: Heather | last post by:
I am creating a database with a backend and frontend. The backend consists of a Products table and many other tables. The products table in an .mdb file by itself is over 2 meg. I thought about...
8
by: Brian S. Smith | last post by:
Hi gang, Please help. I've been through the Access help, searched the Web, and I can't seem to get a straight answer. As the Subject line suggests, I want to run a fairly simple VB/Access Sub...
6
by: Gary T. | last post by:
I have 3 tables: tbl_customer -CustID -fkeyMarketingID -CompName -CompAddr -ContactName -ContactAddr -Ph
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
7
by: Ron | last post by:
Hi All, Using Access2000, winXP. Table 1 = tblClients displayed on frmClients via qryClients. 2nd table = tblInvoices shown on frmInvoices via qryInvoices. 2nd table = tblDetails shown on...
7
by: rewalk | last post by:
Hello all! First thank you to everyone in this community that has been helping me over the past few days. It's greatly appreciated and I've learned a lot. At the moment I'm trying to write some SQL...
4
by: PW | last post by:
Hi, I set up a relationship between two tables with the itineraryid fields in both tables: tblDailyItinerary tblDailyMeals I have a form that writes a record to tblDailyItinerary that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.