Results 1 to 7 of 7
  1. #1
    cunning is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    4

    Creating a relationship with 2 primary keys

    I'm supposed to create a relationship between these two tables with the relationship being StudentID (Transfer student as primary & Transfer School as related)


    with enforce referential integrity. I keep getting this error code. I'm not sure what I am doing wrong or what error did I make. Any advice would help. Thank you
    https://youtu.be/qrrUcxv1awE <-------- video of the steps i took. (at the end when creating a query I'm supposed to end up with 144+ records)

    Click image for larger version. 

Name:	Error Code Access.jpg 
Views:	23 
Size:	96.6 KB 
ID:	26738Click image for larger version. 

Name:	Transfer School Table.jpg 
Views:	23 
Size:	182.8 KB 
ID:	26737Click image for larger version. 

Name:	Transfer Students Table.jpg 
Views:	23 
Size:	295.9 KB 
ID:	26739

    Click image for larger version. 

Name:	Book.jpg 
Views:	14 
Size:	147.8 KB 
ID:	26742(To the left is the 2nd page, the right side is the start of the excercise) Sorry
    Last edited by cunning; 12-15-2016 at 11:45 AM. Reason: Just took a pic of the exercise

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    The error is because there are one or more records that violate the rule you're trying to apply. Try the unmatched query wizard to find them.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The problem is that the TransferStudent table has the field "StudentID" as the PK field AND "TransferSchool.StudentID" is also a PK field.

    "TransferSchool.StudentID" should be a FK (foreign key) field.
    Add an autonumber field to the "TransferSchool" table and set THAT field to be the Primary Key (PK) field.
    Make "TransferSchool.StudentID" a Number (Long Integer type) field. Then you should be able to set the relationship.


    ...........PK.(the one)................................... FK (the many)
    TransferStudent.StudentID ----------->> TransferSchool.StudentID

    or if this helps
    (TransferStudent.StudentID_PK ----------->> TransferSchool.StudentID_FK)

  4. #4
    cunning is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    4
    Thank you for your reply. I am looking into making a foreign key but it asks me to ensure StudentID (TansferSchool Table) has a data type short text so I can't change it a Number data type. Other rule is to set it up as a one-to-one relationship.
    &

  5. #5
    cunning is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    4
    Thanks for the reply. & Yes. the record for Transfer Students table is 302 & Transfer students only has 41. I have to create a relationship between the two StudentID. (Transfer School being primary). I'll try the unmatched query.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If now sounds like the "StudentID" fields (both) are text fields. Try NOT having the "StudentID" fields as the PK field. Then like the fields.

  7. #7
    cunning is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    4
    Thank you for posting again, helped me gain more knowledge about PK & how it functions. Unfortunately the book contained an error.
    I was told to just create the relationship the opposite way. (Transfer school -> Transfer Student) which I knew it worked but the query does not contain all the records so that's what threw me off.
    Thanks again.

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

Similar Threads

  1. Use of primary keys
    By Homegrownandy in forum Access
    Replies: 6
    Last Post: 06-29-2015, 01:17 AM
  2. Two primary keys to the same field?
    By Access_Novice in forum Queries
    Replies: 9
    Last Post: 10-30-2014, 05:40 PM
  3. Replies: 19
    Last Post: 03-11-2014, 10:02 PM
  4. Replies: 3
    Last Post: 09-25-2012, 05:24 PM
  5. primary/foreign keys
    By st1300 in forum Database Design
    Replies: 38
    Last Post: 12-04-2011, 01:27 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