Results 1 to 10 of 10
  1. #1
    donnti is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    8

    relationships

    i'm new to access, i am trying to create a relationship between two tables. I'm trying to Connect the primary key of Books (Book_Number) to the (Book_Number) in Borrowed_Books table.
    it wont let me enforce referential integrity and i don't know why. i have all the same numbers so i don't really understand the popup that i am getting.


    can anyone tell me what is wrong with the two fields that is not letting me create a relationship between them with referential integrity?
    Library Database.accdb

  2. #2
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Is this the error you're getting?

    Click image for larger version. 

Name:	DataError.png 
Views:	12 
Size:	59.5 KB 
ID:	27950

    What are you trying to cascade? If you delete a book from the library it deletes all the books with the same ID from Borrowed books?

  3. #3
    donnti is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    8
    i'm not sure what it means to cascade.
    i'm only trying to enforce referential integrity bc they are meant to be the books from the table.
    the employee id and customer id worked so i dont know why book id is not letting me create a relationship the same way

  4. #4
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by donnti View Post
    i'm not sure what it means to cascade.
    i'm only trying to enforce referential integrity bc they are meant to be the books from the table.
    the employee id and customer id worked so i dont know why book id is not letting me create a relationship the same way
    What i meant by "cascade" is that when you delete a record from the main table (books) it cascades through and deletes all the references from the related table.

    So when you delete a book, it deletes it from the borrowed books table as well.

    I'm assuming your borrowed books table is the books from your inventory that are loaned out?




    Sent from my iPhone using Tapatalk

  5. #5
    donnti is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    8
    yes the borrowed books has Book ID to show which book was borrowed, so i have the book table that is supposed to be where the IDs are coming from, so i am trying to create a relationship but i'm getting that popup
    i was trying to recreate this database DVDRENTALS (2).zip
    i pretty much followed exactly what is in these tables with my own data and they were able to have DVDs related to the DVD ID in the rental table so i just was wondering if there was something wrong with my tables
    Attached Files Attached Files

  6. #6
    donnti is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    8
    should i have set the relationships before i filled the tables?

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The problem is this:

    Your Borrowed_Book table shows book number 24 has been borrowed, but there is no book 24 in the Books table. That is the situation causing a "violation of referential integrity" message.

    In a one-to-many relationship (which you have), referential integrity means that every record on the "Many" side (Borrowed_Books) must have a matching record on the "One" side (Books), when looking at the field(s) which define the relationship. If you ask Access to "Enforce Referential Integrity", it will not let you add a record to the Borrowed_Books table if the book is not in the Books table first.

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    should i have set the relationships before i filled the tables?
    No, it doesn't matter. Referring to my post #8 above, if you add a Book #24 to Books (or delete the record for book 24 from Borrowed_Books), you should be able to create the relationship with no problem.

  9. #9
    donnti is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    8
    thank you!

  10. #10
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Good catch John G! I didn't even think to look at the actual data as the source of the problem. Donnti, make sure to set this list to "solved" if that fixed it for you.


    Sent from my iPhone using Tapatalk

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

Similar Threads

  1. Replies: 7
    Last Post: 08-05-2016, 11:53 AM
  2. Replies: 2
    Last Post: 07-27-2016, 10:25 AM
  3. Explicit Relationships and Implicit Relationships
    By Dazza666 in forum Database Design
    Replies: 2
    Last Post: 07-17-2013, 02:11 AM
  4. Relationships again
    By BarbT in forum Access
    Replies: 2
    Last Post: 11-09-2010, 04:12 AM
  5. One to many relationships
    By CoachBarker in forum Database Design
    Replies: 1
    Last Post: 09-13-2010, 09:01 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