Referential Integrity logic

S

Sally

A slight variation to my earlier post. Access2000 split db. I've test out several times and found that Ref Int. holds true in forms built from a single table or a query with a single table. But if I add in a second table, RefIntegrity is no longer enforced for the form. It still is from the table

I need to be able to prevent users from deleting a record and leaving holes in the db. I hope this post is a bit more specific for any help.
 
J

John Vinson

A slight variation to my earlier post. Access2000 split db. I've test out several times and found that Ref Int. holds true in forms built from a single table or a query with a single table. But if I add in a second table, RefIntegrity is no longer enforced for the form. It still is from the table.

I need to be able to prevent users from deleting a record and leaving holes in the db. I hope this post is a bit more specific for any help.

Irony department:

Your message "msg unavailable" is returning "message unavailable" on
my newsreader... :-{(

Please post the SQL of the query which is failing to enforce RI, and
an example of data which displays this anomaly. Note also that RI is
not enforced for FORMS - it's enforced for TABLES; the form is just a
window on the data in the table.
 
T

Tim Ferguson

Ref Int. holds true in forms built from a single table or a query
with a single table. But if I add in a second table, RefIntegrity is
no longer enforced for the form.

This just does not make sense. Given that Referential Integrity is a
feature of the relationship between two tables, there is no meaning to it
"holding true in forms built from a single table". RI is maintained by the
db engine, and has nothing to do with forms.

What exactly are you trying to do, and what exactly is not working for you?

B Wishes


Tim F
 
S

Sally

I started over and created a simple db design and see how in the form if you try to delete a record w/RI established a msg box appears. When I take this logic back to this large form with many subforms, tabs & multiple queries it doesn't happen
MainTable: FN, LN, Address, etc
DepositTable: Date, type, Amount using MainID to lookup to Main Tabl
PatientHistory:...UnableToSpeak, DateOfDeath, etc

I've set RI so I can't delete a Main record that has deposit or patientHistory connected to it
But when I go in the central form (following is the SQL), it does allow me to delete the MainID record

At this point, I've made the form property as Deletions - NO, but I'm confused as to why it doesn't handle it as expected and what else I might have done to impact it

Thank you
SELECT [TBL Main Table].MainID, [TBL Main Table].TypeID, [TBL Main Table].Prefix, [TBL Main Table].LastName, [TBL Main Table].FirstName, [TBL Main Table].MiddleInt, [TBL Main Table].Suffix, [TBL Main Table].ProfDesig, [TBL Main Table].NickName, [TBL Main Table].Birthdate, [TBL Main Table].PriRelationshipID, [TBL Main Table].JobTitle, [TBL Main Table].CompanyName, [TBL Main Table].Address, [TBL Main Table].LocationID, [TBL Counties].CountyName, [TBL Main Table].PrimaryPhoneNumber, [TBL Main Table].PrimaryPhoneType, [TBL Main Table].FaxNumber, [TBL Main Table].AltPhoneNumber, [TBL Main Table].AltPhoneType, [TBL Main Table].EMail, [TBL Main Table].SecContactID, [TBL Main Table].Addressee, [TBL Main Table].AckSalutation, [TBL Main Table].PatientID, [TBL Main Table].RecordStatus, [TBL Main Table].InactiveDate, [TBL Main Table].InactiveNotes, [TBL Main Table].BusAddress, [TBL Main Table].BusLocationID, [TBL Main Table].BusPhone, [TBL Main Table].BusExt, [TBL Main Table].BusFax, [TBL Main Table].BusEmail, [TBL Main Table].PreferredMailing, [TBL Main Table].ReferralFromID, [TBL Location_1].State, [TBL Location].State, [TBL Location].RegionID, [TBL Location].CountyID, [TBL SecContacts].SecContactFN, [TBL SecContacts].SecContactRelationshipID, [TBL SecContacts].SecContactMI, [TBL SecContacts].SecContactLN, [TBL SecContacts].SecContactPhone, [TBL SecContacts].SecPhoneType, [TBL SecContacts].SecFaxNumber, [TBL SecContacts].SecPrefix, [TBL SecContacts].SecContactFN, [TBL SecContacts].SecContactLN, [TBL SecContacts].SecProfDesig, [TBL SecContacts].SecSuffix, [TBL SecContacts].SecNickName, [TBL Main Table].DateRecordEntered, [TBL Main Table].DateRecordModified, [TBL Main Table].ReceiveNewsletter, [TBL Main Table].MiscNotes, [TBL Main Table].PreferredVendor, [TBL Main Table].BusMatchGift, [TBL Main Table].BusCoDist, [TBL Main Table].BusAZHomeOffice, [TBL SecContacts].SecContactCoMatchGift, [TBL SecContacts].SecContactCoDist, [TBL SecContacts].SecContactCoAZHomeOffice, [TBL Region].Region, [TBL Main Table].BusOtherContact, [TBL Main Table].RemoveFromMailingList, [TBL Main Table].DonorDevID, [TBL SecContacts].SecPrefMailing, [TBL Main Table].BusGivingCyclePref, [TBL SecContacts].SecConGiftCyclePref, [TBL Main Table].SpecialHandling, [TBL Main Table].BusWebSite, [TBL Main Table].NextOfKinID, [TBL Main Table].NextOfKinPriOrSec, [TBL Main Table].NextOfKinRelationship, [TBL NextOfKin].Address, IIf([Tbl Main Table]![NextOfKinPriOrSec]=1 And [Tbl NextOfKin]![PreferredMailing]="Business",[TBL NextOfKin]![BusAddress],IIf([TBL Main Table]![NextOfKinPriOrSec]=2 And [Tbl NOKSecContact]![secPrefMailing]="Business",[TBL NOKSecContact]![SecContactBusAddress],[TBL NextOfKin]![Address])) AS PrefAddress, IIf([Tbl Main Table]![NextOfKinPriOrSec]=1 And [Tbl NextOfKin]![PreferredMailing]="Business",[NOKBusLoc]![City] & " " & [NOKBusLoc]![State] & " " & [NOKBusLoc]![Zip],IIf([TBL Main Table]![NextOfKinPriOrSec]=2 And [Tbl NOKSecContact]![secPrefMailing]="Business",[NOKSecBusLoc]![City] & " " & [NOKSecBusLoc]![State] & " " & [NOKSecBusLoc]![Zip],[TBL NOKLocation]![City] & ", " & [TBL NOKLocation]![STate] & " " & [TBL NOKLocation]![Zip])) AS NextOfKinLocation, [TBL NextOfKin].PrimaryPhoneNumber, [Tbl NOKSecContact]!SecContactFN & " " & [TBL NOKSEcContact]!SecContactLN AS NOKSecContact, [TBL Main Table].pALSContactRelationship, [TBL Main Table].pALSContact, [TBL Main Table].SupportGroupInterest, [TBL PatientHistory].DateOfDeath, [TBL Main Table].RecordSource, [TBL Main Table].TestRecord, [TBL Main Table].Verified, [TBL Main Table].ALSConnectionID, [TBL Main Table].StartDate, [TBL Main Table].EndDate, [TBL Main Table].EmpStatusID, [TBL Main Table].EventNotes, [TBL Main Table].Caregiver, [TBL Main Table].CGPriSec, [TBL Main Table].CGStatus, [TBL PatientHistory].PatientUnableToSpea
FROM (([TBL Counties] RIGHT JOIN (((([TBL SecContacts] AS [TBL NOKSecContact] RIGHT JOIN [TBL Main Table] AS [TBL NextOfKin] ON [TBL NOKSecContact].SecContactID = [TBL NextOfKin].SecContactID) LEFT JOIN [TBL Location] AS [TBL NOKLocation] ON [TBL NextOfKin].LocationID = [TBL NOKLocation].LocationID) RIGHT JOIN ([TBL Region] RIGHT JOIN ([TBL Location] AS [TBL Location_1] RIGHT JOIN ([TBL SecContacts] RIGHT JOIN ([TBL Location] RIGHT JOIN [TBL Main Table] ON [TBL Location].LocationID = [TBL Main Table].LocationID) ON [TBL SecContacts].SecContactID = [TBL Main Table].SecContactID) ON [TBL Location_1].LocationID = [TBL Main Table].BusLocationID) ON [TBL Region].RegionID = [TBL Location].RegionID) ON [TBL NextOfKin].MainID = [TBL Main Table].NextOfKinID) LEFT JOIN [TBL PatientHistory] ON [TBL Main Table].MainID = [TBL PatientHistory].MainID) ON [TBL Counties].CountyID = [TBL Location].CountyID) LEFT JOIN [TBL Location] AS NOKSecBusLoc ON [TBL NOKSecContact].LocationID = NOKSecBusLoc.LocationID) LEFT JOIN [TBL Location] AS NOKBusLoc ON [TBL NextOfKin].BusLocationID = NOKBusLoc.LocationID
WHERE ((([TBL Main Table].TestRecord)=False))
ORDER BY [TBL Main Table].LastName, [TBL Main Table].FirstName, [TBL Main Table].CompanyName;
 
J

John Vinson

FROM (([TBL Counties] RIGHT JOIN (((([TBL SecContacts] AS [TBL NOKSecContact] RIGHT JOIN [TBL Main Table] AS [TBL NextOfKin] ON [TBL NOKSecContact].SecContactID = [TBL NextOfKin].SecContactID) LEFT JOIN [TBL Location] AS [TBL NOKLocation] ON [TBL NextOfKin].LocationID = [TBL NOKLocation].LocationID) RIGHT JOIN ([TBL Region] RIGHT JOIN ([TBL Location] AS [TBL Location_1] RIGHT JOIN ([TBL SecContacts] RIGHT JOIN ([TBL Location] RIGHT JOIN [TBL Main Table] ON [TBL Location].LocationID = [TBL Main Table].LocationID) ON [TBL SecContacts].SecContactID = [TBL Main Table].SecContactID) ON [TBL Location_1].LocationID = [TBL Main Table].BusLocationID) ON [TBL Region].RegionID = [TBL Location].RegionID) ON [TBL NextOfKin].MainID = [TBL Main Table].NextOfKinID) LEFT JOIN [TBL PatientHistory] ON [TBL Main Table].MainID = [TBL PatientHistory].MainID) ON [TBL Counties].CountyID = [TBL Location].CountyID) LEFT JOIN [TBL Location] AS NOKSecBusLoc ON [TBL NOKSecContact].LocationID =
NOKSecBusLoc.LocationID) LEFT JOIN [TBL Location] AS NOKBusLoc ON [TBL NextOfKin].BusLocationID = NOKBusLoc.LocationID

You are NOT seeing "the table" on your Form. When you delete a record
on the form is it in fact being deleted from the table? Is it in fact
leaving orphan records in the related table? Which related table?

You're seeing the records in a multitable join query. I'm startled
that this query isn't giving you an "ambiguous outer joins" message
and even more startled that it's updatebale at all!

Just looking at this, I can't figure out all the relationship
dependencies: but I will say that it's probably a Bad Idea to base a
Form on such a complex query. That's what Combo Boxes (for lookup
tables such as [TBL Location]) and Subforms (for dependent tables such
as [Next Of Kin] are for.
 
S

Sally

When I tried to delete a record in the Main form, it gives the msg "about to delete...", but when I close the form and reopen it, the record is still in the Main Table and reappears. The related record from the Patient History table is now deleted. I noticed that the query that supports the Main Form does not show RI in the join lines between the tables in the query grid. Is this because the RI relationship was established after the query was created?
 
J

John Vinson

When I tried to delete a record in the Main form, it gives the msg "about to delete...", but when I close the form and reopen it, the record is still in the Main Table and reappears. The related record from the Patient History table is now deleted. I noticed that the query that supports the Main Form does not show RI in the join lines between the tables in the query grid. Is this because the RI relationship was established after the query was created?

The query grid does not (ever, in my experience) show RI. As I
suspected, Access is deleting the "manyest" table record, not the
"one" table record. Since you're deleting from the "many" side of a
one to many relationship, no relational integrity constraints are
being violated - you're deleting a leaf, not a trunk.

Use a form with subforms. It will be A WHOLE LOT EASIER to tell what
you're deleting.
 
S

Sally

Thx for your help. Because I didn't establish RI before, the mess of the data was confusing some of the issues. I appreciate your clarification. In the query grid, when it shows the 1 to infinite symbol, I thought that indicated RI has been established in the tables. Otherwise you just get a solid black line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top