Results 1 to 9 of 9
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    Is it always bad to NOT enforce referential integrity?


    I have two tables, 'Timesheet' and 'Paid.' I have a compound index on both tables consisting of name & date & taskCode set to unique values. When I try to link them in relationships, and enforce referential integrity, I get an error message saying: data in the paid table violates referential integrity rules. For example there may be records relating to an employee in the related table, but no record for the employee in the primary table. I guess a way around this is to not enforce referential integrity. Is this bad or is this ok? Keep in mind, I have timesheet data with hours and paid data with hours and I am trying to pair them up, to account for what has been paid.

    Additionally (and I think this ties into the problem above), I have some records in the 'timesheet' table that do not appear in the 'Paid' table and vice versa. I also have some records that appear on both tables.

    I do not want to show only matches, or all records from only one table. I want to show all records from both tables so that I can see matches and mismatches both ways.

    I thought about doing a compound index on just name & date, in order to be less selective, but that would result in repeating values in both tables so I don't think that would be an option.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    No.

    Apparently, those two tables do not have a parent/child dependent relationship. Why would records be in Paid if there is no associated Timesheet record?

    Many experienced developers don't even bother to set up relationships and instead rely on design of forms and code to control data integrity and restricting user access to the tables and queries.
    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
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you plan on letting other developers have access to your tables via linking or ODBC, you will want to consider constraints at the table level. Otherwise, I prefer maintaining Referential Integrity and managing Constraints via VBA.

  4. #4
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by June7 View Post
    No.

    Apparently, those two tables do not have a parent/child dependent relationship. Why would records be in Paid if there is no associated Timesheet record
    But I am able to relate them by using a compound index, and they are definitely related because timesheet hours incurred are eventually paid and I'm trying to reconcile them.

    The data for the timesheets table comes from my companies system. The data for the Paid table, comes from the clients system. So the only common denominators I have to work with are name, date and taskCode.

    Under Edit Relationships, I can show only matches or all records from one table, and matches from the other. Is there a way to show all records from both tables (matches and mismatches)? There has got to be a way to do this, because I need to show everything that is out there.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    If you want these tables to have referential integrity then need to clean up the child table and eliminate orphans or add parent records to the other table before setting the relationship.

    Do Find Unmatched query to locate the orphans. There is a query wizard to help.
    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.

  6. #6
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by June7 View Post
    If you want these tables to have referential integrity then need to clean up the child table and eliminate orphans or add parent records to the other table before setting the relationship.

    Do Find Unmatched query to locate the orphans. There is a query wizard to help.
    Good suggestion. You have been very helpful. Thank you.

  7. #7
    ButtonMoon is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2013
    Posts
    17
    Quote Originally Posted by Access_Novice View Post
    But I am able to relate them by using a compound index, and they are definitely related because timesheet hours incurred are eventually paid and I'm trying to reconcile them.
    The problem here is that "relationships" (in the Access sense) have nothing to do with referential integrity. The thing called a relationship in the Access UI is actually a fairly pointless feature for predefining a type of join between tables in the database. It's something that didn't ought to exist in any relational database. Unfortunately perhaps, to enforce referential integrity through the Access UI you first have to create a relationship and then check the "enforce" option. If you are inclined to try it you can bypass this "feature" by using SQL DDL statements in a query window - but not surprisingly, many people will find that too much trouble.

    My recommendation: don't create relationships unless you intend to enforce referential integrity (RI). If you do want to enforce RI then it is better to do it in the database rather than in a form or application. Doing it in the database means you create the constraint once and it applies everywhere. You don't have to maintain the rule separately in every application and you don't need to worry about any data getting into the table that doesn't satisfy the RI constraint.

  8. #8
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by ButtonMoon View Post
    The problem here is that "relationships" (in the Access sense) have nothing to do with referential integrity. The thing called a relationship in the Access UI is actually a fairly pointless feature for predefining a type of join between tables in the database. It's something that didn't ought to exist in any relational database. Unfortunately perhaps, to enforce referential integrity through the Access UI you first have to create a relationship and then check the "enforce" option. If you are inclined to try it you can bypass this "feature" by using SQL DDL statements in a query window - but not surprisingly, many people will find that too much trouble.

    My recommendation: don't create relationships unless you intend to enforce referential integrity (RI). If you do want to enforce RI then it is better to do it in the database rather than in a form or application. Doing it in the database means you create the constraint once and it applies everywhere. You don't have to maintain the rule separately in every application and you don't need to worry about any data getting into the table that doesn't satisfy the RI constraint.
    You gave a lot of interesting insight. Thank you. I was always under the impression that if you have multiple tables, that each table had to be related to at least one other table. I appreciate your insight.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    There likely are relationships but setting them in the Relationship Builder is not required.
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-18-2013, 05:56 AM
  2. Referential Integrity
    By YunqHero in forum Forms
    Replies: 4
    Last Post: 12-17-2012, 05:05 PM
  3. Referential Integrity
    By Desstro in forum Database Design
    Replies: 4
    Last Post: 06-13-2010, 01:29 PM
  4. Referential Integrity
    By U810190 in forum Access
    Replies: 1
    Last Post: 03-29-2010, 05:21 PM
  5. Referential Integrity
    By jbarrum in forum Access
    Replies: 5
    Last Post: 01-14-2010, 09:04 AM

Tags for this Thread

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