Results 1 to 4 of 4
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494

    What is best for Primary key


    I have a database that has several tables
    Railcars
    Customers
    Assignments
    Contacts

    Each railcar is unique with a Initial and Number. Is it best to use these two together to make a primary key or is it better to just assign each railcar an uniqu ID number?
    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    I don't like compound (composite) keys but that is my personal preference. Two fields isn't so bad but that's about as far as I would permit if I absolutely had to use. I have one table that would use 5 fields as unique identifier. In this case I went with Autonumber field as pk.

    In my biggest db (the main reason for my job) is a program generated identifier as primary key. This is a 'number' assigned to a material sample logged in for testing. The structure is YYYYA-####. The sequential number part starts over from 1 each year. In 30 years this ID structure has not failed. Never exceeded 4500 in any year. Not my design but it works for our requirements.
    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.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Further to June7's comment, a Primary key is primarily for use by the Database software. If the primary key you are considering can change (ever), then use another construct for the Primary Key. It is very possible to have a system assigned autonumber (guaranteed unique by the database software) and still have the fields that mean something to you --initial + railcarNumber -- for your use (just not the primary key). If there is a number welded onto the railcar, that may be the primary key. Often when the developer concocts a "string" with some built-in intelligence --Number - letter-number 0-9 etc to be a PK, it fails because some condition evolves and negates that key/string (no longer unique or some part of the string no longer applies).

    Lots to think about when selecting the PK.
    Good luck.

    Here's a tutorial that you may find useful
    http://www.rogersaccesslibrary.com/T...lationship.zip

    If you are mathematical, there is a free video with more of the "rationale" and "meaning" of Primary Keys and relations at
    http://shop.oreilly.com/product/0636920002710.do (It the free first part of others -very good but based in mathematics)
    NOTE: Autonumbers are not necessarily incremental nor positive-- they are unique)

    Every table has a primary key that uniquely identifies each row in that table.

  4. #4
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    494
    Thank orange, that was a good read.
    The car number initial combo will never change - if it does it would be entered as a new car. However, I think I will go with a single autonumber field to make sure it is as clean and simple as possible.
    thanks for the hellp

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

Similar Threads

  1. Number as a primary key.
    By Booster in forum Database Design
    Replies: 1
    Last Post: 05-22-2012, 04:38 AM
  2. Primary key
    By Sara_IT in forum Access
    Replies: 2
    Last Post: 11-25-2011, 02:46 PM
  3. Primary Key
    By DukeBlue in forum Access
    Replies: 18
    Last Post: 09-23-2011, 05:23 PM
  4. Primary Key Help
    By phoenix13 in forum Access
    Replies: 4
    Last Post: 07-30-2009, 12:36 PM
  5. about the primary key!
    By Yuesko in forum Access
    Replies: 1
    Last Post: 05-29-2009, 04:20 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