Results 1 to 9 of 9
  1. #1
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43

    Relating fields by text instead of ID


    Is it a bad practice to have tables related by a text field, specifically in this case alpha numeric part numbers like ABC123H, ABC124H, XYZ12C, etc. It would make importing data much easier, based on the fact that if I go by the Auto-numbered ID, I don't have the ID available for each part number until I've already imported some of the data. Is there a significant performance degradation by relating via "short text" datatypes? I'm just trying to follow some best practices guidelines while coming up with schema for the database structure. I could easily still have the tables have an Autonumber ID, but just not use it for table relationships.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    You can relate by text field.
    It doesnt have to be a key.

  3. #3
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    As a personal preference I always use Autonumber as the PK on every table.

    Also I name the field as, for example PKCars or PKBottles.

    The foreign key would be FKTrains etc

    Every table should have a PK.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I have used text field as PK/FK and have no issues. However, performance might get slower with very large dataset because numbers index faster.
    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.

  5. #5
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691

    Follow Up

    Quote Originally Posted by btappan View Post
    Is it a bad practice to have tables related by a text field, specifically in this case alpha numeric part numbers like ABC123H, ABC124H, XYZ12C, etc. It would make importing data much easier, based on the fact that if I go by the Auto-numbered ID, I don't have the ID available for each part number until I've already imported some of the data. Is there a significant performance degradation by relating via "short text" datatypes? I'm just trying to follow some best practices guidelines while coming up with schema for the database structure. I could easily still have the tables have an Autonumber ID, but just not use it for table relationships.
    I was just wondering which way you went. Number or Text

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Are you having to import multiple related tables?

    I had situation where I had to import data from multiple databases that used autonumber PK. Had to write a bunch of VBA code to maintain relationships.

    Then another situation importing from multiple databases that used text fields as PK/FK. This certainly did make import much simpler.
    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.

  7. #7
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Are we talking import or update.

    Importing should be easy with either Text or Number.

    Updating is another story.

    Regardless of what you are doing I would still recommend Autonumber as the Primary key. It is so much easier to relate to other tables using a unique number rather that Text which may not be unique.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I too always use an autonumber type field as the PK field in tables. And I use a suffixs of "_PK" and "_FK". Much easier to see how tables are linked and a lot easier to select linking fields when setting up a main form-sub form link.
    See Microsoft Access Tables: Primary Key Tips and Techniques

  9. #9
    Peter M is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2017
    Posts
    67
    I know this thread is a little old, but I would be very interested if people have any performance tests showing that an alpha-numeric primary key is slower than an autonumber key.

    Personally I have not seen a difference and use text-PKs all the time. As the original poster noted, if you are importing data, it is much easier to use an existing ID as the primary/foreign key.
    I ran a simple query to see if I could find a difference with the following setup:

    Base_Table - 6.5 million records
    TextID (Short text, 17 characters) - Unique Primary ID
    GrouperField (short text, 255)
    GrouperAmount (currency)

    LastUser_Table - 1.3 million records
    TextID (short text, PK)
    Name (short text, 255)

    Query:

    Join Base_Table and LastUser_Table on TextID
    Sum GrouperAmount by Name

    I made a table that was a replica of Base_Table plus an auto-number field as the PK. There was no discernible performance difference, even when I applied manipulation to the TextID like Group By mid (TextID,7,5).

    (Now to be fully transparent, none of these queries took more than 2 minutes to complete so it wasn't a really good test.)

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

Similar Threads

  1. Replies: 5
    Last Post: 07-14-2019, 05:22 PM
  2. Grouping/relating fields
    By jbzy324 in forum Database Design
    Replies: 4
    Last Post: 06-12-2014, 12:12 PM
  3. Relating similar fields???
    By smoothlarryhughes in forum Access
    Replies: 10
    Last Post: 02-26-2013, 12:50 PM
  4. relating fields from one table to a form
    By ljmellor in forum Forms
    Replies: 11
    Last Post: 12-06-2012, 03:55 PM
  5. Database design- need help relating fields
    By sebeckett in forum Access
    Replies: 5
    Last Post: 09-02-2011, 02:21 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