INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Designing a table's primary key.

Designing a table's primary key.

(OP)
After 10 or so years of using Access the potential problem of releying on the Autonumber for my tables primary key has become clear. Following a table corrpution I called up a backup, pasted in some records and then realsied that the records did not share the same autonumber as before(Access had jumped the deleted records in the autonumber field). This then made the relationships in my tables loose their integrity.

I have not thought of this issue before and I have commonly constructed tables using an autonumer as my primary key and linked from this. i.e. CustomersID etc...

Access 2010 allows table data macros and so I see that I can have an autonumber at the start of a new record which sets a number field using a table level data macro when an insert event is triggered - (which I can set as primary key).

Would this be a safer and more desirable way of setting a tables primary key? Or if someone has a better suggestion?

Many thanks Mark

RE: Designing a table's primary key.

You should let the primary key be autonumbered. However, you can build your own keys as well. Your own key should be used to join to other tables. Classic example:

Order Table
OrderKey (autogenerated)
OrderNumber (primary key)
OrderDate
CustomerID
etc

OrderDetail Table
OrderDetailKey (autogenerated)
OrderNumber (with OrderItem the primary key)
OrderItem (with OrderNumber the primary key)
ItemQuantity
ItemPrice
etc

Customer Table
CustomerKey
CustomerID (primary key)
CustomerType
CustomerCity
etc.

==================================
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright


RE: Designing a table's primary key.

You may also find handy resetting the autonumber in Access.
More info about it here

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: Designing a table's primary key.

(OP)
Thanks all

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close