Problems with relationships, please help!

sirantonycartwr

Registered User.
Local time
Today, 12:15
Joined
Dec 10, 2006
Messages
45
Hello, Firstly, heres my ER-D thing:
relationship.JPG

The problem, is with the relationship between:
stakeholders and bookings.
stakeholders and stakeholders letters.

when i join stakeholders and bookings it says one to one, i want a stakeholder to have many bookings not just one, however, i havent tested this yet.

when i join stakeholders and stakeholders letters its also one to one, but thats ok because i want it to be. When i make a form, it always wants me to enter the stakeholder ID for stakeholder letters, i want it to do that automatically, why wont it do it?

Can anyone give me any suggestions?
Ant...
 
The problem with the Stakeholder booking is probably that you have StakeholderID set as the primary key when it should be a foreign key.
 
In general, when Access sees a relationship between two fields, it can tell by the uniqueness criteria on the fields whether the relationship should be one//one or one//many. If the relationship is between the prime keys of both tables, then you always get one//one because prime keys must be unique. (You can't build a many//many relationship directly, though you could do so through something called a JUNCTION TABLE. But that isn't your question so I'll ignore that option.)

Here's the bottom line: If the ID field is unique in both tables, that is where your problem lies. I can't confirm this because your ERD won't show us the uniqueness, only that something is a key.

I'm going to digress to explain the fine point of design that governs this choice of keys.

The general rule is, no matter whether the field is a prime key in any OTHER table, if it is going to be part of a one//many relationship, it must be treated as a foreign key on the many-side table. For which it can still be indexed but with duplicates allowed.

The other side of that same rule is that generally, a key is prime/unique in one and only one table. It is foreign or else is part of a compound key in all other tables that reference it. The table in which the key is prime is the table that describes the thing to which that key refers. E.g. if you have a stakeholder ID, it would be unique only in the table of stakeholders, nowhere else.

Why? Because with very few exceptions, anywhere else in the database, it cannot be the prime key by itself.

Why can't it be prime by itself elsewhere? Well, this is a fine point of design and some folks might not fully agree with this because it verges in to the ART (not science) of database design.

If the records in two tables depend completely and only on the same field, you have or imply a one//one relationship between those tables - which actually is rare. Not unheard of, but rare. It ALSO means the tables are individually incomplete. Bear with me on this one.

The immediate question is why you didn't merge the two tables by adding fields or records to accomodate the extra data. This is because of key selection rules about uniqueness and completeness.

In a properly designed and fully normalized database, the records of any one table depend uniquely and completely on the prime key. If you have TWO tables that meet this criterion for the same exact key and the same exact VALUES for that key, then the two tables are each PARTIAL descriptors of the thing uniquely and completely described by that single key. Which says that the tables taken individually are incomplete.

Now, if one of the two tables using the same prime key is SPARSE - i.e. sometimes blank, or if the data in one of the tables doesn't get used very often, these are excuses for the layout being split into two tables with the same exact key. These are the rare cases. (In the sparse case, this is still a problem since in that case the key in the sparse table should be treated as one//many anyway - because otherwise JOINs won't work right.)
 
Thanks for your quick responses.

The problem with the Stakeholder booking is probably that you have StakeholderID set as the primary key when it should be a foreign key.

Thats not the problem, the problem with that was that for some reason Stakeholder ID was indexed with no duplicates!?!? Dunno why? I must of accidentally ticked it. Anyway ive just unticked it, enforced fererencial integrity and booking works 100%. Excellent.

The doc man:
Thanks mate. I know about junction tables etc. I dont think they are appropriate here. (Sorry, that sounds sharp, but i cant rephrase it!)

However...

Now, if one of the two tables using the same prime key is SPARSE - i.e. sometimes blank, or if the data in one of the tables doesn't get used very often, these are excuses for the layout being split into two tables with the same exact key. These are the rare cases. (In the sparse case, this is still a problem since in that case the key in the sparse table should be treated as one//many anyway - because otherwise JOINs won't work right.)

This is the case, the data (in the letters table) is split from the mother table (stakeholders table) because only special stakeholders have a reference in the letters table. Id say half stakeholders have a reference to the letters table, out of these 50% only 5% will need to have letters sent. The reason i split the tables was because of this.

What can i do about it?
Please suggest...
Ant...
 
Didn't think you needed junction tables either, which is why I avoided it. As to "sharp" or not, the nature of this forum requires brevity. When I see a brief answer, no big deal.

Yes, indexing gets you every time when the relationship cardinality doesn't meet your expectation. (Well, ALMOST every time...)

Good luck on your project.
 

Users who are viewing this thread

Back
Top Bottom