Results 1 to 10 of 10
  1. #1
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94

    Cool Update PK in Tble 1 and Tble 2

    I have two related tables and I have approx 30 records that I wanted to update the PK (intended to change one by one)


    I created a simple select query based on the two tables and tried to update the two PK fields but sau cant as related
    I tried googling but nothing suitable came up
    Can anyone help with a query to change one PK and the related PK is updated automatically
    Many Thanks in advance

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Please provide more info. The purpose of a PK is to uniquely identify a record in a table. It is something that should not be changed generally.
    please tell us the exceptional circumstances that require you to change a PK.

    Code:
    In the world of databases, the primary key of a relational table uniquely identifies each record in the table.
     Databases use keys to compare, sort, and store records, and to create relationships between records. 
    Choosing the primary key in a database is one of the most important steps in the process.

  3. #3
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    In the data set of 9000 records 8970 have a PK of 9 digits. There is 30 records with a PK from 1 to 30

    I wanted to update these PK from 1-30 to a 9 character PK in both tables that are linked to make them a similar structure

    They do not referance any other table

    Hope that helps

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Please describe the 2 tables. What o they represent? Why do they need to have the same structure?
    How are the 9 digits determined?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    When linking fields, one is PK and one is FK. Is the PK an autonumber type? It is possible to set value in autonumber field with UPDATE or INSERT sql. Then must run Compact & Repair to reset the auto number seed. Autonumber or not, an UPDATE sql should do want you want.

    If these tables are 1-to-1 relation, why have two tables?
    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.

  6. #6
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    The data relate to spare parts data that was downloaded from the inventory system to Excel as a single table.
    As I will review the data and make changes to descriptions, stock categories etc. I made a 2nd table with all the new fields plus the stock Item No (PK) from table 1

    The stock Item No is 9 digits long is unstructured

    In the received XLS there are 30 stock item nos coded from 1 to 30 (not sure how who created these..............I want to make these also 9 digits in both tables

    I can always remove the table relationships and edit these 30 items in each table, but was hoping there was a better way



    Hope this helps

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Only 30 records? Not autonumber field? I would just manually edit.

    Probably have to first remove relationship regardless.
    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.

  8. #8
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    Arghhhh
    PK as received in Excel short description
    why have two tables ............getting more complicated
    I have done some freebie master data audits so have a front end with loads of queries that can look at different back ends (representing a freebie audit)
    Reason for two tables is table 1 is generic fields and table 2 new data fields or non standard data fields as different companies have different data

    Can you clarify if I have stock No in Table 1 and is the PK should the FK also be the Stock Item No or should it be autogenerated???

    Many Thanks

    Perhaps getting too complicated and I thank everyone for their input and will rethink

  9. #9
    DaveT99 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    94
    Okay VIP
    I was going to do that but wondered if there was a cleverer way

    Thanks for all the help

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Yes, the clever way is to run UPDATE query, but is it really worth effort to build for only 30 records?
    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. Replies: 2
    Last Post: 06-21-2018, 03:16 AM
  2. Replies: 2
    Last Post: 08-03-2017, 04:58 AM
  3. Replies: 1
    Last Post: 10-27-2016, 12:14 PM
  4. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  5. Replies: 1
    Last Post: 01-22-2011, 12:23 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