Results 1 to 5 of 5
  1. #1
    YunqHero's Avatar
    YunqHero is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Location
    Owings Mills, MD
    Posts
    3

    Post Referential Integrity

    How does referential integrity prevent mistakes in a database?

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Referential integrity enforces the relationships between tables and prevents orphaned records by 'structurally' enforcing that relationship between the 2 relationally joined tables. You cannot delete a record in a main table unless the relational record has first been deleted which keeps the data in synch. Orphaned records are one of the main reasons for inaccurate counts and mistakes in the data.

  3. #3
    YunqHero's Avatar
    YunqHero is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Location
    Owings Mills, MD
    Posts
    3
    pkstormy, Thank you.

  4. #4
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Your welcome. There is probably a more in-depth, politically correct explanation of this somewhere on the web. This is more of how I tend to think of it.

  5. #5
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Quote Originally Posted by pkstormy View Post
    Referential integrity enforces the relationships between tables and prevents orphaned records by 'structurally' enforcing that relationship between the 2 relationally joined tables. You cannot delete a record in a main table unless the relational record has first been deleted which keeps the data in synch. Orphaned records are one of the main reasons for inaccurate counts and mistakes in the data.
    As an added note: You can setup a relationship to cascade delete which will always automatically delete the record(s) in the relational table first and then delete the main record. Another thing Referential Integrity will check is when entering new records in the relational table it checks that the value entered in the relationally joined field has a matching value in the main table.

    If you try to create relationships and there are orphaned or unmatched values in the relational records on that field, you'll get an error. If it does let you create this relationship with orphaned records or the integrity rules were broken (which I've rarely seen), I would follow these steps:

    Easy method:
    1. Delete and re-create the relationship. Check integrity by manually entering records into the tables.

    More involved method:
    1. first clean all orphaned records in all relational tables.
    2. Consider creating a new db and then importing all the tables (without any relationships - ie. click the Options button)
    3. Then create the relationships for all the relational tables. MSAccess 2010 does a good job on checking for bad data.

    or to a higher degree:
    Create a new db and all the tables along with the relationships. Then import all the data from the old tables into each table (you may have to save all the old autonumber values (that have relationships) into a new field in each table so it can be used to link the old data with the new data and grab the new autonumber value in your append queries - not for MSAccess beginners.)

    When the referential integrity rules have been broken it's usually a sign of something going wrong structural with the database. I've only seen it broken about 1/2 dozen times in the last 25 years working with different data structures, usually in an older (MSAccess 97 mdb or with a corrupt mdb.) I would not trust that deleting and re-creating the relationship would resolve the issue. Typically there are signs of other problems when this happens.

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

Similar Threads

  1. Referential Integrity
    By Paul H in forum Database Design
    Replies: 3
    Last Post: 11-14-2011, 03:07 PM
  2. referential integrity
    By askjacq in forum Database Design
    Replies: 1
    Last Post: 10-14-2011, 03:23 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

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