473,396 Members | 2,158 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,396 software developers and data experts.

Referential Integrity and Indexes

Hi
I have created a database for my kids to keep track of their swim team races. We use this to keep track of their speeds by stroke, fastest times, averages, etc.

I am trying to add a new module, pulled from a form, created from a query, that will calculate if they have qualified for district championships or not. The module works fine, but I cannot write the calculated results back to the table. I think the problem is with my table relationships.

As set up I cannot write any data from my query results back to the table. I need to change some of my data fields to unique indexes to accomplish what I wish, but I don't see how to do that with my current structure.

I have four (4) tables:

tblSwimmer
SwimmerID (key)
GirlorBoy
etc

tblSwimTeam
SwimTeamID (key)
SwimmerID
AgeSwimmingAs
etc

tblIndividualRaces
IndivRacesID (key)
SwimTeamID
Stroke
etc

tblQualifyingTimes
QTID (key)
Sex
Age
Stroke
etc

As each swimmer can be on more than one swim team (different seasons) I have a one to many relation between tblSwimmer.SwimmerID and tblSwimTeam.SwimmerID, and as each swimmer will have many races for the team I have a one to many relation between tblSwimTeam.SwimTeamID and tblIndivRaces.SwimTeamID.

When I create one to one relationships between tblQualifyingTimes:sex and tblSwimmer:GirlorBoy, tbl QualifyingTimes:Age and tblSwimTeam:AgeSwimmingAs, and tblQualifyingTimes:Stroke and tblIndivRaces:Stroke I get the correct results from my query but am unable to write anything back to my table. My problem is that Access wants the columns from the parent tables to be unique indexes, but I don't see how this is possible.

I have also tried writing a subquery to match up the correct QTID with IndivRacesID, but run into the same problem as above when I try to write this to my form. I have also tried putting QTID in tblIndividualRaces but as it is null in that table initially I would have to write to that column.

Is there a better way to set up my relationships? Does anyone see a different workaround?

Thank You
Ivan
Aug 30 '06 #1
10 2102
MMcCarthy
14,534 Expert Mod 8TB
What is your key in tblQualifyingTimes tying it to one of your other table. (eg Foreign Key of SwimmerID)

Hi
I have created a database for my kids to keep track of their swim team races. We use this to keep track of their speeds by stroke, fastest times, averages, etc.

I am trying to add a new module, pulled from a form, created from a query, that will calculate if they have qualified for district championships or not. The module works fine, but I cannot write the calculated results back to the table. I think the problem is with my table relationships.

As set up I cannot write any data from my query results back to the table. I need to change some of my data fields to unique indexes to accomplish what I wish, but I don't see how to do that with my current structure.

I have four (4) tables:

tblSwimmer
SwimmerID (key)
GirlorBoy
etc

tblSwimTeam
SwimTeamID (key)
SwimmerID
AgeSwimmingAs
etc

tblIndividualRaces
IndivRacesID (key)
SwimTeamID
Stroke
etc

tblQualifyingTimes
QTID (key)
Sex
Age
Stroke
etc

As each swimmer can be on more than one swim team (different seasons) I have a one to many relation between tblSwimmer.SwimmerID and tblSwimTeam.SwimmerID, and as each swimmer will have many races for the team I have a one to many relation between tblSwimTeam.SwimTeamID and tblIndivRaces.SwimTeamID.

When I create one to one relationships between tblQualifyingTimes:sex and tblSwimmer:GirlorBoy, tbl QualifyingTimes:Age and tblSwimTeam:AgeSwimmingAs, and tblQualifyingTimes:Stroke and tblIndivRaces:Stroke I get the correct results from my query but am unable to write anything back to my table. My problem is that Access wants the columns from the parent tables to be unique indexes, but I don't see how this is possible.

I have also tried writing a subquery to match up the correct QTID with IndivRacesID, but run into the same problem as above when I try to write this to my form. I have also tried putting QTID in tblIndividualRaces but as it is null in that table initially I would have to write to that column.

Is there a better way to set up my relationships? Does anyone see a different workaround?

Thank You
Ivan
Aug 30 '06 #2
Hi - Thanks for the reply

I had set up a one to many relationship between QTID in tblQualifyingTimes and the foriegn key of QTID in tblIndividualRaces. But as the qualifying info is all new, the QTID in tblIndividualRaces is currently null, and each new entry would be null as the children are entering their race information. I can pick out the correct QTID and times using a query where I have deleted the relationship between QTID in tblQualifyingTimes and the foriegn key of QTID in tblIndividualRaces but I need a way of witing the QTID in tblIndividualRaces. Or a way of just taking the times associated with the QTID and using them in my module.

Thanks
Ivan
Aug 30 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
If a Qualifying Time relates to tblIndividualRaces then does it not also relate to tblSwimTeam.

Hi - Thanks for the reply

I had set up a one to many relationship between QTID in tblQualifyingTimes and the foriegn key of QTID in tblIndividualRaces. But as the qualifying info is all new, the QTID in tblIndividualRaces is currently null, and each new entry would be null as the children are entering their race information. I can pick out the correct QTID and times using a query where I have deleted the relationship between QTID in tblQualifyingTimes and the foriegn key of QTID in tblIndividualRaces but I need a way of witing the QTID in tblIndividualRaces. Or a way of just taking the times associated with the QTID and using them in my module.

Thanks
Ivan
Aug 30 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
To clarify, is this logic correct

A swimmer is on a swim team
A team is in an individual race
A team has a qualifying time in that individual race


Hi - Thanks for the reply

I had set up a one to many relationship between QTID in tblQualifyingTimes and the foriegn key of QTID in tblIndividualRaces. But as the qualifying info is all new, the QTID in tblIndividualRaces is currently null, and each new entry would be null as the children are entering their race information. I can pick out the correct QTID and times using a query where I have deleted the relationship between QTID in tblQualifyingTimes and the foriegn key of QTID in tblIndividualRaces but I need a way of witing the QTID in tblIndividualRaces. Or a way of just taking the times associated with the QTID and using them in my module.

Thanks
Ivan
Aug 30 '06 #5
To clarify:
1. Each swimmer can be on more than one swim team (different seasons).
2. For each swim team, each swimmer will swim many individual races.
3. During a season, each race may be swum multiple times.
4. There is only one qualifying time associated with each individual race.
5. The same qualifying time may be used with each new race.
6. The selection of which qualifying time to use is dependent on a). Is the swimmer a boy or a girl b). The age of the swimmer and c). the stroke for that race.
7. The way the program is currently set up, the swimmer enters if they are a boy or girl only one, in tblSwimmer.
8.Each new season, the swimmer enters the age they are swimming as only once, in tblSwimTeam.
9. After their individual races the swimmer enters the race data including stroke, in tblIndividualRaces.
10. I then want Access to select the correct qualifying time from tblQualifyingTime to send to my module.
11. The module calculates if they qualified for regional championships or not and also lets them know the time difference between their race and the qualifying times.

I have created two different queries, one bases on joins and the other using the "In" commandto get the correct qualifying times or QTID. Both of these work only if there is no table relationship between tblQualifyingTimes and the other tables.

What I want to do is use either QTID or the times associated with it in my module to calculate and update records in tblIndividualRaces.

Thank You
Ivan
Aug 30 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Firstly, because each swimmer can be on more that one team and each team has more than on swimmer the relationship between tblSwimmer and tblSwimTeam is many to many. You will need to create a join table with a double primary key made up of SwimmerID and SwimTeamID.

The tblQualifyingTimes needs to have a relationship both to the Swimmer and the Race. That is a Foreign key to tblSwimmer (SwimmerID) and a Foreign Key to tblIndividualRaces (IndivRacesID).

Although a team swims a race the qualifying time is the swimmer therefore the foreign key in tblIndividualRaces shouldn't be a foreign key to the SwimTeam in this table. I would suggest setting up a transaction table that would replace the table tblQualifyingTimes. As long as it holds the foreign keys described above it would allow you to join all records.

To clarify:
1. Each swimmer can be on more than one swim team (different seasons).
2. For each swim team, each swimmer will swim many individual races.
3. During a season, each race may be swum multiple times.
4. There is only one qualifying time associated with each individual race.
5. The same qualifying time may be used with each new race.
6. The selection of which qualifying time to use is dependent on a). Is the swimmer a boy or a girl b). The age of the swimmer and c). the stroke for that race.
7. The way the program is currently set up, the swimmer enters if they are a boy or girl only one, in tblSwimmer.
8.Each new season, the swimmer enters the age they are swimming as only once, in tblSwimTeam.
9. After their individual races the swimmer enters the race data including stroke, in tblIndividualRaces.
10. I then want Access to select the correct qualifying time from tblQualifyingTime to send to my module.
11. The module calculates if they qualified for regional championships or not and also lets them know the time difference between their race and the qualifying times.

I have created two different queries, one bases on joins and the other using the "In" commandto get the correct qualifying times or QTID. Both of these work only if there is no table relationship between tblQualifyingTimes and the other tables.

What I want to do is use either QTID or the times associated with it in my module to calculate and update records in tblIndividualRaces.

Thank You
Ivan
Aug 30 '06 #7
Thank You for your reply

This was first written for only my daughter so the one to many between swimmers and swim team made sense. But now that we have several kids on the team using it you're right, I need a many to many relationship.

Regarding the qualifying times, I have tried the transition table previously and again just now and am able to maintain referential integrity that way. But the problem is that since the data in tblQualifyingTimes is not generated by the user, it is a lookup table only, Access must determine which qualifying time or QTID to use for each individual race - IndividualRacesID. Until Access does this calculation the QTID record associated with the IndividualRacesID in the transition table is not populated.

The only ways I have come up with so far to calculate QTID are using queries where there is no table relaionship between tblQualifyingTimes and the other tables. I can get the correct QTID but cannot get Access to populate the null QTID associated with the IndividualRacesID.

I have assumed it was because of the lack of referential integrity in my queries, but I could be wrong. I am trying to get this to work as easily and seamlessly as possible since these are kids entering the data.

Again, any help is appreciated
Ivan
Aug 30 '06 #8
MMcCarthy
14,534 Expert Mod 8TB
If you have a triple Primary Key on the Transaction table comprising QTID, SwimmerID, IndivRaceID then Access will provide the referential integrity when the Qualifying time is updated. On the add new record to this table you will have to provide a swimmer and race or you cannot add the record.



Thank You for your reply

This was first written for only my daughter so the one to many between swimmers and swim team made sense. But now that we have several kids on the team using it you're right, I need a many to many relationship.

Regarding the qualifying times, I have tried the transition table previously and again just now and am able to maintain referential integrity that way. But the problem is that since the data in tblQualifyingTimes is not generated by the user, it is a lookup table only, Access must determine which qualifying time or QTID to use for each individual race - IndividualRacesID. Until Access does this calculation the QTID record associated with the IndividualRacesID in the transition table is not populated.

The only ways I have come up with so far to calculate QTID are using queries where there is no table relaionship between tblQualifyingTimes and the other tables. I can get the correct QTID but cannot get Access to populate the null QTID associated with the IndividualRacesID.

I have assumed it was because of the lack of referential integrity in my queries, but I could be wrong. I am trying to get this to work as easily and seamlessly as possible since these are kids entering the data.

Again, any help is appreciated
Ivan
Aug 31 '06 #9
I guess I got hung up on trying to have the query itself have some sort of referential integrity, but what you suggest is much better. Thank you for your help.
Ivan
Sep 2 '06 #10
MMcCarthy
14,534 Expert Mod 8TB
The thing to remember is your tables all have to have referential integrity you can't impose it a query level.


I guess I got hung up on trying to have the query itself have some sort of referential integrity, but what you suggest is much better. Thank you for your help.
Ivan
Sep 2 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

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: Jimmie H. Apsey | last post by:
Referential Integrity on one of our production tables seems to have been lost. I am running Postgres 7.1.3 embedded within Red Hat kernel-2.4.9-e.49. Within that I have a table with referential...
5
by: Geisler, Jim | last post by:
So, as far as I know, PostgreSQL does not have any way of verifying the loss of referential integrity. Are there any recommended methods or utilities for checking referential integrity in a...
6
by: heyvinay | last post by:
I have transaction table where the rows entered into the transaction can come a result of changes that take place if four different tables. So the situation is as follows: Transaction Table...
80
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used...
3
by: moskie | last post by:
Is there a way to run an alter table statement that adds a constraint for a foreign key, but does *not* check the existing data for refrential integrity? I'm essentially looking for the equivalent...
3
by: shsandeep | last post by:
In a data warehousing application, what is the impact of imposing referential integrity on the database side? Does it help or degrade the performance considering the complex transformations that...
6
by: CPAccess | last post by:
How do I maintain referential integrity between a main form and a subform, each based upon different (but joined with integrity enforced) table? Here's the situation: I have two tables:...
3
by: Wayne | last post by:
I've inadvertently placed this post in another similar newgroup, and I apologise if you get it twice. I'm building a database that consists of frontend and backend. Some of the lookup tables...
2
by: ApexData | last post by:
Access2000, using a continuous form. I’m getting a message that say “you cannot add or change a record because a related record is required in table Employee”. This occurs in all my combobox...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.