Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2014
    Posts
    8

    Question Would it be possible (about relationship in Ms. Access)?

    Can I use non primary key as foreign key exactly like no. 1 and 2 in this picture below?
    I still remember that my teacher said non primary key can't be used as foreign key,
    but I look this in a book and I often look this on internet that non primary key is used as foreign key.


    can anyone experts help me?


    I'd be really grateful if anybody could help.




    Click image for larger version. 

Name:	relationship.jpg 
Views:	18 
Size:	42.6 KB 
ID:	16168

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Yes, you can use the relationships as you have shown, no problem. It's my own opinion, but in the Product table, if ProductCode is relatively short, and uniquely identifies the products, then you can use it as the PK - you don't need ProductID.

    Not so for Supplier, though. A supplier name tends to be long, so you should use SupplierID as the PK. In your Purchase table, I would replace SupplierName with SupplierID, and use that in the relationship. You can always use a query or a DLookup to get the supplier name when you need it.

    HTH

    John

  3. #3
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    Foreign keys should be a candidate key of another table, but not necessarily the primary key. A candidate key is any field that uniquely identifies a record. Foreign keys should refer to a candidate key that is unique and that cannot be null.

    IMO, keep your autonumber primary keys, and design your forms in a way that will display meaningful fields rather than meaningless autonumbers, but will store those autonumber keys.

  4. #4
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Just to reiterate in case it's not clear.

    YES you can use another field on the table for the foreign key relationship, however it MUST be unique and non-nullable. You cannot have any duplicate values in that field and you cannot allow any nulls in that field.

  5. #5
    Join Date
    Apr 2014
    Posts
    8
    Thank you all!

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

Similar Threads

  1. Replies: 4
    Last Post: 10-22-2012, 11:52 PM
  2. Replies: 4
    Last Post: 09-05-2012, 07:26 AM
  3. Access Relationship Question
    By glassjames in forum Access
    Replies: 2
    Last Post: 05-22-2012, 07:01 PM
  4. Relationship problems in access
    By danish raza in forum Database Design
    Replies: 1
    Last Post: 07-10-2011, 05:50 AM
  5. Access Table - Relationship Question
    By vixtran in forum Database Design
    Replies: 5
    Last Post: 06-12-2009, 10:10 PM

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