Sign Up |  Live StatsLive Stats    Articles 34,874| Comments 154,820| Members 17,226, Newest gurjeetgill| Online 329
Home Contact
 (Forgotten?): 
    Sikhism

   
                                                                     Your Banner Here!    

 
 
  
  

Primary Keys

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 400 USD, Received: 25 USD (6%)
Please Donate...
Related Topics...
Thread Thread Starter Forum Replies Last Post
The Ten Keys To Lasting Happiness Soul_jyot Spiritual Articles 2 07-Mar-2008 23:35 PM
send Keys problem Halocarbon Information Technology 6 28-Jul-2006 08:35 AM
Keys - I Keep losing my Keys, Any Ideas? TheNovice Information Technology 1 28-Jul-2006 08:18 AM
Send Keys Max Information Technology 1 28-Jul-2006 08:12 AM
Numeric Values for Primary Keys Only??? CMV Information Technology 1 28-Oct-2005 18:00 PM


Tags
primary, keys
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 28-Jul-2006, 08:34 AM
LurfysMa's Avatar LurfysMa
Guest
 
Posts: n/a
   
   
Primary Keys

  Donate Today!   Email to Friend  Tell a Friend   Show Printable Version  Print   Contact sikhphilosophy.net Administraion for any Suggestions, Ideas, Feedback.  Feedback  

Register to Remove Advertisements
Most of the reference books recommend autonum primary keys, but the
Access help says that any unique keys will work.

What are the tradeoffs?

I have several tables that have unique fields. Can I use them as
primary keys or should I define an autonum primary key?

One table has information about the 50 states in the US. The table
looks like this:

State Capitol Date Admitted
Alabama Montgomery December 14, 1819
Alaska Juneau January 3, 1959
Arizona Phoenix February 14, 1912
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/13100-primary-keys.html

Since the state names are unique, is there any reason not to make that
field the primary key?

Another table has to do with grade school multiplication tables. This
is a simple table something like this:

Factors Answer
1x1 1
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
2x1 2
2x2 4
3x1 3
3x2 6
3x3 9
...
12x1 12
12x2 24
...
12x12 144

Here again, the Factors field (a text field) is unique. Is there any
reason not to use it as the primary key?

In both cases, the tables are small, so adding another 4-byte field is
no big deal, but I'd like to keep the tables as simple as possible
unless there is some downside.

Thanks

--
Running MS Office 2000 Pro on Win2000



 
Do share your immediate thoughts or reactions on this issue? We value your views! Login Now! or Sign Up Today! to share your views with us.. Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 28-Jul-2006, 08:34 AM
Barry Gilbert's Avatar Barry Gilbert
Guest
 
Posts: n/a
   
   
RE: Primary Keys

Using a column that is guaranteed to be unique, as in your examples, will
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
usually work. The one place you would consider using an autonumber is if you
expected to have to change the other key value. I don't expect any states to
change their names any time soon, so it's probably ok there. In your other
example, is there any risk that you might change the values in the factors
field? On the other hand, even if you did need to change something, a
cascading update relationship would still accomodate this.

Bottom line: if you have a candidate field that, by its nature, is
guaranteed to be unique, use it.

Barry


"LurfysMa" wrote:

> Most of the reference books recommend autonum primary keys, but the
> Access help says that any unique keys will work.
>
> What are the tradeoffs?
>
> I have several tables that have unique fields. Can I use them as
> primary keys or should I define an autonum primary key?
>
> One table has information about the 50 states in the US. The table
> looks like this:
>
> State Capitol Date Admitted
> Alabama Montgomery December 14, 1819
> Alaska Juneau January 3, 1959
> Arizona Phoenix February 14, 1912
>
> Since the state names are unique, is there any reason not to make that
> field the primary key?
>
> Another table has to do with grade school multiplication tables. This
> is a simple table something like this:
>
> Factors Answer
> 1x1 1
> 2x1 2
> 2x2 4
> 3x1 3
> 3x2 6
> 3x3 9
> ...
> 12x1 12
> 12x2 24
> ...
> 12x12 144
>
> Here again, the Factors field (a text field) is unique. Is there any
> reason not to use it as the primary key?
>
> In both cases, the tables are small, so adding another 4-byte field is
> no big deal, but I'd like to keep the tables as simple as possible
> unless there is some downside.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
>
> Thanks
>
> --
> Running MS Office 2000 Pro on Win2000
>

Reply With Quote
  #3 (permalink)  
Old 28-Jul-2006, 08:34 AM
Amy Blankenship's Avatar Amy Blankenship
Guest
 
Posts: n/a
   
   
Re: Primary Keys

In my opinion, you're asking for trouble if you ever show the user the
primary key or if you might ever want to edit that information. Since
primary keys are normally the way you establish relationships, you don't
want them to ever change once a record has been created. Even though you
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
may think the key value won't change, typos have been known to happen.
Also, number fields take up less space in the database and primary keys, as
the source of the relationship, are typically repeated over and over in many
tables.

Therefore, I always use autonumbers. Other opinions vary.

HTH;

Amy

"LurfysMa" wrote in message
news:1f8ab25mq18uhqv6ml1qo5lu4gj782i53d@4ax.com...
> Most of the reference books recommend autonum primary keys, but the
> Access help says that any unique keys will work.
>
> What are the tradeoffs?
>
> I have several tables that have unique fields. Can I use them as
> primary keys or should I define an autonum primary key?
>
> One table has information about the 50 states in the US. The table
> looks like this:
>
> State Capitol Date Admitted
> Alabama Montgomery December 14, 1819
> Alaska Juneau January 3, 1959
> Arizona Phoenix February 14, 1912
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
>
> Since the state names are unique, is there any reason not to make that
> field the primary key?
>
> Another table has to do with grade school multiplication tables. This
> is a simple table something like this:
>
> Factors Answer
> 1x1 1
> 2x1 2
> 2x2 4
> 3x1 3
> 3x2 6
> 3x3 9
> ...
> 12x1 12
> 12x2 24
> ...
> 12x12 144
>
> Here again, the Factors field (a text field) is unique. Is there any
> reason not to use it as the primary key?
>
> In both cases, the tables are small, so adding another 4-byte field is
> no big deal, but I'd like to keep the tables as simple as possible
> unless there is some downside.
>
> Thanks
>
> --
> Running MS Office 2000 Pro on Win2000



Reply With Quote
  #4 (permalink)  
Old 28-Jul-2006, 08:34 AM
LurfysMa's Avatar LurfysMa
Guest
 
Posts: n/a
   
   
Re: Primary Keys

On Wed, 12 Jul 2006 11:48:27 -0500, "Amy Blankenship"
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
wrote:

>In my opinion, you're asking for trouble if you ever show the user the
>primary key


Why is merely showing the user the primary key a problem?

--
Running MS Office 2000 Pro on Win2000
Reply With Quote
  #5 (permalink)  
Old 28-Jul-2006, 08:34 AM
RoyVidar's Avatar RoyVidar
Guest
 
Posts: n/a
   
   
Re: Primary Keys

> Most of the reference books recommend autonum primary keys, but the
> Access help says that any unique keys will work.
>
> What are the tradeoffs?
>
> I have several tables that have unique fields. Can I use them as
> primary keys or should I define an autonum primary key?
>
> One table has information about the 50 states in the US. The table
> looks like this:
>
> State Capitol Date Admitted
> Alabama Montgomery December 14, 1819
> Alaska Juneau January 3, 1959
> Arizona Phoenix February 14, 1912
>
> Since the state names are unique, is there any reason not to make
> that field the primary key?
>
> Another table has to do with grade school multiplication tables. This
> is a simple table something like this:
>
> Factors Answer
> 1x1 1
> 2x1 2
> 2x2 4
> 3x1 3
> 3x2 6
> 3x3 9
> ...
> 12x1 12
> 12x2 24
> ...
> 12x12 144
>
> Here again, the Factors field (a text field) is unique. Is there any
> reason not to use it as the primary key?
>
> In both cases, the tables are small, so adding another 4-byte field
> is no big deal, but I'd like to keep the tables as simple as possible
> unless there is some downside.
>
> Thanks


I'd recommend you to take the time to use your favourite search engine
for the terms like "natural vs surrogate primary key". Such search
will
probably list some of the pros and cons, in addition to hours of fun
;-)

Basically, some favours usage of surrogate keys (Autonumber), others
favours natural keys, which represents "things" having a business
meaning, and which can also be a combination of fields. Some (including
me) will use both, based upon the requirements. For state, I'd probably
use the two letter code.

Just be aware - for some this isn't just a matter of preference, it's
religion to a degree thats close to fanatism.

Just be sure that if you decide upon surrogate key (Autonumber), then
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
remember that this will not ensure the integrity of your data! It will
only ensure that each record has a unique number. Say in a table where
you have a unique field, but you decide to add an Autonumber field for
primary key, you will need to also add a unique index on the "natural
key" field in addition to the primary key index on the Autonumber
field,
else you'll risk dupes.

--
Roy-Vidar


Reply With Quote
  #6 (permalink)  
Old 28-Jul-2006, 08:34 AM
KARL DEWEY's Avatar KARL DEWEY
Guest
 
Posts: n/a
   
   
RE: Primary Keys

Primary keys build an index and if you are concerned with database size then
two letter abbreviation for the state would be a smaller index.

I have another case for your in that I have to keep training certifications
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
and occupational examination records on personnel. But they keep changing
departments, names, employee code when migrating to different subcontractors,
etc. I set up an alias table that will have all changes and you can see that
the database records reflect that Jane Doe, now married to Bill Smith, had
hearing exam last year. The data matches paper records. There is a new
alias record for every change and the front/top displays the latest always
with a subform showing the current and all previous aliases.

"LurfysMa" wrote:

> Most of the reference books recommend autonum primary keys, but the
> Access help says that any unique keys will work.
>
> What are the tradeoffs?
>
> I have several tables that have unique fields. Can I use them as
> primary keys or should I define an autonum primary key?
>
> One table has information about the 50 states in the US. The table
> looks like this:
>
> State Capitol Date Admitted
> Alabama Montgomery December 14, 1819
> Alaska Juneau January 3, 1959
> Arizona Phoenix February 14, 1912
>
> Since the state names are unique, is there any reason not to make that
> field the primary key?
>
> Another table has to do with grade school multiplication tables. This
> is a simple table something like this:
>
> Factors Answer
> 1x1 1
> 2x1 2
> 2x2 4
> 3x1 3
> 3x2 6
> 3x3 9
> ...
> 12x1 12
> 12x2 24
> ...
> 12x12 144
>
> Here again, the Factors field (a text field) is unique. Is there any
> reason not to use it as the primary key?
>
> In both cases, the tables are small, so adding another 4-byte field is
> no big deal, but I'd like to keep the tables as simple as possible
> unless there is some downside.
>
> Thanks
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
>
> --
> Running MS Office 2000 Pro on Win2000
>

Reply With Quote
  #7 (permalink)  
Old 28-Jul-2006, 08:34 AM
LurfysMa's Avatar LurfysMa
Guest
 
Posts: n/a
   
   
Re: Primary Keys

On Wed, 12 Jul 2006 1002 -0700, KARL DEWEY
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
wrote:

>Primary keys build an index and if you are concerned with database size then
>two letter abbreviation for the state would be a smaller index.


Since there are only 50 states, the savings would be negligible even
if we annex Canada one day! ;-)

I was more interested in usage and reliability tradeoffs.

>I have another case for your in that I have to keep training certifications
>and occupational examination records on personnel. But they keep changing
>departments, names, employee code when migrating to different subcontractors,
>etc. I set up an alias table that will have all changes and you can see that
>the database records reflect that Jane Doe, now married to Bill Smith, had
>hearing exam last year. The data matches paper records. There is a new
>alias record for every change and the front/top displays the latest always
>with a subform showing the current and all previous aliases.


Sounds messy...

--
Running MS Office 2000 Pro on Win2000
Reply With Quote
  #8 (permalink)  
Old 28-Jul-2006, 08:34 AM
Amy Blankenship's Avatar Amy Blankenship
Guest
 
Posts: n/a
   
   
Re: Primary Keys

Because by user I mean people other than the developer who might be charged
with maintaining your data. When you show something to that type of user,
you lay it open to being changed. Here's a full discussion of the issue
http://www.dbpd.com/vault/9805xtra.htm

"LurfysMa" wrote in message
news:4naab29a2jtsda1ecc6k2umesi533v0v4j@4ax.com...
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
> On Wed, 12 Jul 2006 11:48:27 -0500, "Amy Blankenship"
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
> wrote:
>
>>In my opinion, you're asking for trouble if you ever show the user the
>>primary key

>
> Why is merely showing the user the primary key a problem?
>
> --
> Running MS Office 2000 Pro on Win2000



Reply With Quote
  #9 (permalink)  
Old 28-Jul-2006, 08:34 AM
Larry Linson's Avatar Larry Linson
Guest
 
Posts: n/a
   
   
Re: Primary Keys

"LurfysMa" wrote

> Since there are only 50 states, the
> savings would be negligible even
> if we annex Canada one day! ;-)


Your mileage may vary, but I've never done a database using states where I
did not, sooner or later, need the state abbreviation, as well as other
information. And, just for the record, my much-used and
much-copied-from-database-to-database "state" lookup table is actually a
table of "US states and Canadian provinces" and, any day now, I may have a
client who will need Mexican states and their abbreviations, too.

In any case, since I need them anyway, I index on the state/province
abbreviation which may give a very minute performance advantage -- it
certainly will not be very significant.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100

Larry Linson
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
Microsoft Access MVP


Reply With Quote
  #10 (permalink)  
Old 28-Jul-2006, 08:34 AM
Douglas J Steele's Avatar Douglas J Steele
Guest
 
Posts: n/a
   
   
Re: Primary Keys

  Donate Today!  
Just to play devil's advocate, at least two of the official provincial
abbreviations have changed in Canada in recent memory (Quebec used to be PQ,
and now is QC, Newfoundland and Labrador used to be NF, and now is NL). We
also got a 3rd territory a few years back, but an addition to the table
isn't as bad as a change to the PK.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13100


"Larry Linson" wrote in message
news:O2pg7zdpGHA.1548@TK2MSFTNGP04.phx.gbl...
> "LurfysMa" wrote
>
> > Since there are only 50 states, the
> > savings would be negligible even
> > if we annex Canada one day! ;-)

>
> Your mileage may vary, but I've never done a database using states where I
> did not, sooner or later, need the state abbreviation, as well as other
> information. And, just for the record, my much-used and
> much-copied-from-database-to-database "state" lookup table is actually a
> table of "US states and Canadian provinces" and, any day now, I may have a
> client who will need Mexican states and their abbreviations, too.
>
> In any case, since I need them anyway, I index on the state/province
> abbreviation which may give a very minute performance advantage -- it
> certainly will not be very significant.
>
> Larry Linson
> Microsoft Access MVP
>
>



Reply With Quote
   Click Here to Donate Now!

Support Us!
Become a Promoter!
Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh!
ReplyPost New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!

Bookmarks


(View-All Members who have read this thread : 0
There are no names to display.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Tools Search
Search:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

» Gurbani Jukebox
Listen to Gurbani while surfing SPN!
» Recent Discussions
sikhism Benti Chaupai - Keertan...
Today 19:55 PM
8 Replies, 171 Views
sikhism A village where every...
Today 19:12 PM
0 Replies, 9 Views
Why have Sikhs Changed...
Today 18:12 PM
34 Replies, 1,148 Views
Fools Who Wrangle Over...
Today 17:38 PM
910 Replies, 77,770 Views
Turban Cloth
Today 17:22 PM
3 Replies, 57 Views
Is Hindu/Sikh a Valid...
Today 16:40 PM
79 Replies, 1,376 Views
Scientists cure cancer,...
By Kamala
Today 14:09 PM
7 Replies, 118 Views
Any Japji Sahib videos...
By Kamala
Today 13:02 PM
6 Replies, 62 Views
SGPC Recruitment Scandal
Today 04:09 AM
0 Replies, 48 Views
Sukhmani Sahib Astpadi 8...
Today 01:43 AM
0 Replies, 43 Views
Why Nathuram Godse...
Today 01:23 AM
3 Replies, 189 Views
Are Nihangs: A Legacy...
Yesterday 23:30 PM
11 Replies, 233 Views
Sukhmani Sahib: 10th...
Yesterday 22:27 PM
0 Replies, 54 Views
Zafarnama..
Yesterday 21:33 PM
0 Replies, 94 Views
Sukhmani Sahib Astpadi 8...
Yesterday 20:37 PM
1 Replies, 67 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.2

All times are GMT +6.5. The time now is 20:30 PM.
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.66941 seconds with 30 queries