Results 1 to 2 of 2
  1. #1
    themebuddies is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    14

    primary and foreign keys?

    I am new to access and designing databases.



    I want to make a database for work that will hold Purchase orders and line numbers. One purchase order can have many line numbers. From my reading, I would think that my database should look like this

    tblPurchaseOrders
    ordersID
    Purchase Orders

    tblLineItems
    lineID
    line Numbers
    ordersFK

    if I am correct, then the primary key ( ordersID ) should be linked to the foreign key ( ordersFK ) in the lineItems table in the relationships and to enforce referential integrity. This had made me wonder. The primary key field gets populated automatically when you make a new record. Do I then have to enter in that ID into the foreign key field in the lineItems table? I don't want to have to do that. I want it so that the information gets linked automatically. Is this possible?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,918
    If you establish this relationship in the Relationships window, the tables will be associated and data entry into the subtable will automatically save the PK as FK. However, recommend not working directly with tables and queries. Build bound forms.

    Build a form/subform arrangement. Set the subform container Master/Child Links properties. This will synchronize the related records and the PK will automatically save into the dependent record, even if you don't establish Relationships.
    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. Extracting Foreign Keys
    By QuantifyRisk in forum Forms
    Replies: 7
    Last Post: 08-08-2014, 02:05 PM
  2. Replies: 11
    Last Post: 06-11-2012, 12:23 AM
  3. primary/foreign keys
    By st1300 in forum Database Design
    Replies: 38
    Last Post: 12-04-2011, 01:27 PM
  4. Need help with foreign keys
    By acdougla17 in forum Access
    Replies: 1
    Last Post: 09-26-2011, 03:50 PM
  5. Primary/foreign keys + relationships
    By tripptofer in forum Database Design
    Replies: 0
    Last Post: 08-12-2009, 07:44 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