Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2005, 12:12 AM
Authorized User
 
Join Date: Jan 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thoughts on Primary keys

Hi all,

Usually whenever I design any tables I use Autonumbers as the primary keys. And this works fine for me.

However, in designing this current table, I have the option of using an autonumber field again, or I can use a text field. This text field will probably be no more than 10-15 characters long and this entry is going to be unique.

So my question for all the guru's out there is :

Is it better to use autonumber fields as the primary key, even if there is another field that can serve as the primary key, but it happens to be a text field? (With the aforementioned table design, I'm going to have two indexes and they are both going to be unique)

Just wondering what the impact will be on database performance when joining on text fields instead of numbers?

Also, under what circumstances will it be okay to use a text field as the primary key? Size of the field perhaps??

Cheers

Rohan
__________________
Cheers

Rohan
 
Old February 8th, 2005, 04:28 PM
ru1 ru1 is offline
Authorized User
 
Join Date: Feb 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rohan. You can use a test field for a key anytime you want as long as it is unique. There are no ramifications I can think of off the cuff. I use them all the time. But what I have found is this. If you have an autonumber field, even if it is not a key field, it will for the most part still be unique. So, go ahead and have one with your text field, just don't make it part of your key and it will be there if you decided you need it.

RU1

 
Old February 8th, 2005, 05:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

The fact that you have this unique text field and you're going out of the way to including it in your table sounds like it has some kind of meaning. If that's so, and especially if users will ever see this field, then you do NOT want to use it instead of an autonumber field.

The autonumber field is not seen by users and its sole purpose is to associate other data in other tables to the same record.

Your text field sounds like it's being used (and seen). Stick to having them both and using the autonumber field as the primary key.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old February 9th, 2005, 06:18 PM
Authorized User
 
Join Date: Jan 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys.

After your input and by checking out other newsgroups, I will be using autonumbers as primary keys. It's just going to be safer!!

Cheers

Rohan





Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting records with foreign and primary keys tdaustin Classic ASP Basics 0 October 4th, 2005 12:49 AM
When to define primary keys and foregin keys? method SQL Server 2000 1 August 26th, 2005 09:14 AM
Find() With multiple primary keys busher ASP.NET 1.0 and 1.1 Professional 0 June 2nd, 2005 03:00 PM
ASP and auto-generated primary keys Steve777 Classic ASP Professional 2 May 26th, 2005 10:47 AM
Subform/Links ~ Too Many Primary Keys fdsi19 Access 1 September 30th, 2003 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.