Why use autonumber as a primary key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Accrj19
    New Member
    • Jul 2010
    • 9

    Why use autonumber as a primary key

    Could someone help me understand why using an autonumber field as a primary key is a good idea?

    If you use an autonumber as the PK, won't that allow the possibility of duplicate data being entered into the database? For example, if I have an Orders table, an order could be entered twice and each of these records in the Orders table would have a different autonumber but it would be the same order.

    I hope this makes sense. Thanks.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Both natural keys and surrogate keys have advantages and disadvantages. It is up to you to decide on a case by case basis which one outweighs the other.

    You can refer to this page on wikipedia for more information. https://en.wikipedia.org/wiki/Surrogate_key.

    Usually, the advantages of a surrogate key outweigh the advantages of a natural key. Specifically regarding your situation, that is one of the disadvantages of using a surrogate key over the natural key (which I assume is some sort of order number that you calculate). That particular weakness can be removed by placing a unique index on the natural key. Just because you're using a surrogate key doesn't mean that you have no way of ensuring uniqueness on your natural key.

    If your order number is never going to change, then that could make it a strong candidate to be the primary key.

    Comment

    Working...