Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    bubly1322 is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2024
    Posts
    7

    Enforce referential integrity

    Hello everyone!
    I am new to the Microsoft Access. I have an issue with my database. I cannot create referential integrity; I mean enforce it in my database. I attached a screenshot of my database. The problem is that I have to make the relationship between tblCommunityCensus and tblNaturalAreas, tblSchools, tblCommunityCrime, and tblCommunityServices. All the tables have one common field which is comm_code. The comm_code is PK in the tblCommunityCensus and FK in the rest of the tables. All PK and FK have the same data type and I even checked the missing comm_code and even tried to add them to the child tables but still, I am getting an error sying data in the table 'tblSchools' violates referential integrity rules.. Any advice????



    Click image for larger version. 

Name:	Screenshot 2024-04-15 211427.jpg 
Views:	30 
Size:	102.9 KB 
ID:	51684

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You already have data in tables?

    Why is comm_code a PK in two tables?

    tblCommunityCrime and tblCommunityServices are already related to tblComunitiesByWard.

    tblParkPathways and ...Stops cannot be linked to both tblComunitiesByWard and tblCommunityCensus by same key.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bubly1322 is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2024
    Posts
    7
    Yes, the data is in tables. I tried to make connections between all of the tables. The main point is to connect the tblCommunityCensus to tblNaturalAreas, tblSchools, tblCommunityCrime, tblCommunityServices, tblParkPathways, and tblTransitStops. The connections work between tblCommunityCensus and tblParkPathways, and tblTransitStops but the rest do not.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Makes no sense for a table to be related two master tables on same field.

    Have not addressed my question about comm_code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    madpiet is online now Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    156
    (You're going to hate yourself if you leave all the primary keys as PK.)
    Imagine writing a query and reading it maybe six months from now. What does "PK" mean, or better, Which table does it refer to?

  6. #6
    bubly1322 is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2024
    Posts
    7
    When I wanted to set up the PK for other fields in tblCommunitiesByWard I was getting error saying they would create duplicate values in the index. But I found out that I can change the PK for Name field which I've done already, now PK is Name field and FK comm_code for this table.

  7. #7
    bubly1322 is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2024
    Posts
    7
    Sorry I am new to this

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    And Name is a reserved word. Should not use reserved words as names.

    Also, why have the PK autonumber field if you don't use it as primary key?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,945
    Quote Originally Posted by madpiet View Post
    (You're going to hate yourself if you leave all the primary keys as PK.)
    Imagine writing a query and reading it maybe six months from now. What does "PK" mean, or better, Which table does it refer to?
    Same would apply to comm_code as well would it not?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    bubly1322 is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2024
    Posts
    7
    I tried to do relationships by using PK in tblCommunityCensus with other tables. I had to add the PK fields to other tables because when I tried to set the Primary key by using a different field it was saying they would create duplicate values in the index.
    I try to do a query that will count how many for example schools are in the community (comm_code) in tblCommunityCensus.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    So why is Name field assigned as PK?

    Sorry, I can't make sense of anything you are saying.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    bubly1322 is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2024
    Posts
    7
    Quote Originally Posted by June7 View Post
    So why is Name field assigned as PK?

    Sorry, I can't make sense of anything you are saying.

    Sorry.. I made a little changes so maybe now it will more clear.. No name as Primary key and tblCommunities is a new tblCommunityCensus.
    Click image for larger version. 

Name:	Screenshot 2024-04-16 121016.png 
Views:	22 
Size:	65.3 KB 
ID:	51691

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Okay, that looks better to me. The issue is same?

    Again, could provide db for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    madpiet is online now Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    156
    Maybe post a (sanitized) version of your database. The comm_code in nearly every table? Without seeing the data, it's hard to tell what it means.

  15. #15
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    It's not looking great to me. Aside from the fact that I don't see a tblCommunity_Consensus, I see tables with PK fields and no foreign key for them in any other table. Also see 2 id fields in the same table, repeating fields in tblSchools and question the comm_code being in every table. I question that there is no link between what looks like a one to many (or parent/child if you prefer) between communities and services.

    I think you should review db normalization and see if you can fix all of this, or post a detailed description that explains what it's all about. Whatever explanation you give, expect more questions because there's no way for you to anticipate everything we'd need to know. Maybe start with the links in this thread
    https://www.accessforums.net/showthr...773#post521773
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-11-2021, 11:52 AM
  2. relationships, referential integrity, can't enforce
    By markjkubicki in forum Programming
    Replies: 6
    Last Post: 10-25-2019, 04:40 PM
  3. Enforce Referential Integrity Limit
    By Western_Neil in forum Database Design
    Replies: 8
    Last Post: 05-12-2018, 09:14 AM
  4. Unable to Enforce Referential Integrity
    By DaveT99 in forum Database Design
    Replies: 3
    Last Post: 04-17-2018, 02:34 PM
  5. Is it always bad to NOT enforce referential integrity?
    By Access_Novice in forum Database Design
    Replies: 8
    Last Post: 08-18-2014, 09:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums