473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1953
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
1878
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 -----------------+-----------------------+----------- key_code | character varying(6) | not null date_key_issued | date |
2
3413
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 want them to be linked to the "main" table. Problem is, it won't let me run the SQL run as long as the one-many relationship is established in the relationship window. The SQL is:
4
2470
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 putting the products table in a file by itself and all the other tables in another file. I anticipate there will be a need for changes in the other tables and since communication is over the internet, having the products table in a different file...
8
4316
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 Function/Module that creates relationships for my tables. The problem is that I need to provide for some tables that may have > 32 relationships (which is apparently the limit on Indexes that Access can support). How can I prevent Access from...
6
1884
by: Gary T. | last post by:
I have 3 tables: tbl_customer -CustID -fkeyMarketingID -CompName -CompAddr -ContactName -ContactAddr -Ph
1
3670
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 "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
7
2003
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 subform(to frmInvoices) sfrmDetails via qryDetails. Relationship built between tblClients/tblInvoices/tblDetails by ClientID. Relationship between tblInvoices/tblDetails by InvoiceID. All works fine if
7
6767
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 code to set up the proper relationship between a created table and an existing table. The existing table is called key metrics and it has an autonumber primary key ID. The created table has a field also called ID, which is a number...NOT an...
4
3107
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 updates the autonumber field itineraryid. I then bring up a subform which
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.