Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / March 2006

Tip: Looking for answers? Try searching our database.

PartNumber can be used as primary key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kyle - 20 Feb 2006 03:56 GMT
When setting up a table, can I use actual PartNumber as a primary key instead
of assign one as PartNumberID with data type as autonumber.  I would like to
use actual PartNumber as a primary key.  But..   which way is better?

Any suggestion or recommend.  Thanks.  
Ken Snell (MVP) - 20 Feb 2006 04:52 GMT
If the part numbers are unique identifiers for the parts, then you can use
the part number as the primary key.

As for which is better -- using the part number or a autonumber -- well,
that is a matter of great debate among the developers. I personally have
used both approaches, depending upon my needs.

Signature

       Ken Snell
<MS ACCESS MVP>

> When setting up a table, can I use actual PartNumber as a primary key
> instead
[quoted text clipped - 3 lines]
>
> Any suggestion or recommend.  Thanks.
Rick Brandt - 20 Feb 2006 13:00 GMT
> When setting up a table, can I use actual PartNumber as a primary key
> instead of assign one as PartNumberID with data type as autonumber.
> I would like to use actual PartNumber as a primary key.  But..
> which way is better?
>
> Any suggestion or recommend.  Thanks.

As suggested, it depends.  Here is scenario where it would make a difference.

Let's say you also have a database tracking the history of a part number (design
changes etc..).  Now at some point one of those changes is that the part number
itself is changed.  Should the history database track the entire history (across
both the new and old part number) or should a new history begin from scratch at
the point the number was changed?

If you want the former then you need to be using a surrogate primary key.  If
you want the latter then using the part number is not a problem.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

HaLevi - 21 Feb 2006 17:52 GMT
Expanding the above question if I may,

Is it possible to copy the whole column of autonumber to another column and
then edit it?

(Meaning:  I sell books.  I don't want to have to manually assign thousands
of different numbers to give part numbers for each of my listings.  So if I
use the automatically assigned number for the record as the part number, and
then possibly add a few letters before the given number if necessary that
will tell me what category of book the given part number is in - would that
work?  - Hope I am clear...)
Signature

Thank you,

knuble07

> > When setting up a table, can I use actual PartNumber as a primary key
> > instead of assign one as PartNumberID with data type as autonumber.
[quoted text clipped - 13 lines]
> If you want the former then you need to be using a surrogate primary key.  If
> you want the latter then using the part number is not a problem.
John Vinson - 01 Mar 2006 02:35 GMT
>(Meaning:  I sell books.  I don't want to have to manually assign thousands
>of different numbers to give part numbers for each of my listings.  So if I
>use the automatically assigned number for the record as the part number, and
>then possibly add a few letters before the given number if necessary that
>will tell me what category of book the given part number is in - would that
>work?  - Hope I am clear...)

Well... that is NOT a good idea.

A field should have one purpose ONLY. Storing both a part number and a
category in one field is a violation of this principle. Stoer the part
number in one field; and store the category in a different field.

                 John W. Vinson[MVP]    
Tom Lake - 01 Mar 2006 04:17 GMT
>>(Meaning:  I sell books.  I don't want to have to manually assign
>>thousands
[quoted text clipped - 12 lines]
> category in one field is a violation of this principle. Stoer the part
> number in one field; and store the category in a different field.

He can then use both fields as an aggregate PK.

Tom Lake
John Spencer - 20 Feb 2006 13:05 GMT
Is PartNumber always unique?  If you use two (or more) manufacturers or
suppliers will the part numbers still be unique?  Is part number stable
(that is, it won't change over time)?

If the answers are yes for YOUR database then using PartNumber as the
primary key is probably a good idea.  It will save space, make your queries
simpler since you often will need only the PartNumber and therefore won't
need to add the Parts table to your queries.

> When setting up a table, can I use actual PartNumber as a primary key
> instead
[quoted text clipped - 3 lines]
>
> Any suggestion or recommend.  Thanks.
HaLevi - 21 Feb 2006 20:34 GMT
What are the rules I guess - of the auto assigned numbers in Access?
I have read that once you don't have it in place when you start a database
it is too late to add it after.  So if I want it used in a database that
didn't have it turned on, can I just start a new database and then move that
info in?  Also, can I edit Autonumber?  If I can't then - maybe I wasn't
clear before - then I cannot add the letters in front of it.  In which case,
I want to have Autonumber and then copy the auto assigned number for each new
book automatically into a copy of that in a different column which we'll call
Item Number.

Thank you
Signature

knuble07

> Is PartNumber always unique?  If you use two (or more) manufacturers or
> suppliers will the part numbers still be unique?  Is part number stable
[quoted text clipped - 12 lines]
> >
> > Any suggestion or recommend.  Thanks.
John Spencer - 22 Feb 2006 13:22 GMT
An autonumber in Access is automatically assigned when a record is created
and even if the record is not saved, the number is used up.
The number will be unique for the entire table.
It cannot be edited.

You can add an autonumber field to a table at any time.  I do not know what
algorithm the engine uses to decide which record gets which number - I would
suspect that the numbers are assigned in record storage order, but that is
just a guess.

Autonumbers are NUMBERS and therefore don't contain (and can't) contain any
letters.

Autonumbers often make good primary keys since they are automatically
generated, unique, and stable.  However, they aren't good things to show to
the users since they often have little direct relationship to the data that
is stored in the row.  They are a convenience in establishing and
maintaining relationships between tables.

> What are the rules I guess - of the auto assigned numbers in Access?
> I have read that once you don't have it in place when you start a database
[quoted text clipped - 30 lines]
>> >
>> > Any suggestion or recommend.  Thanks.
Tom Lake - 22 Feb 2006 13:45 GMT
> Autonumbers often make good primary keys since they are automatically generated,
> unique, and stable.  However, they aren't good things to show to the users since
> they often have little direct relationship to the data that is stored in the row.
> They are a convenience in establishing and maintaining relationships between
> tables.

I like my PKs to have some relationship to the data.  Something
like a SSN, or a company-generated PO # or Invoice #.

Autonumber fields have nothing to do with our data and are more
difficult to work with than a field of our own choosing.  Yes,
there's more chance of error when the user is expected to
enter the PK manually but in practice we see no big source of error
here. The PK actually makes sense to the user so the user is more
likely to enter it correctly.

Tom Lake
HaLevi - 22 Feb 2006 14:29 GMT
Dear Mr. Spencer,
How do you add autonumber to a table that already has data in it. When I try
I am denied for the very reason that there is data?
Signature

knuble07

> An autonumber in Access is automatically assigned when a record is created
> and even if the record is not saved, the number is used up.
[quoted text clipped - 49 lines]
> >> >
> >> > Any suggestion or recommend.  Thanks.
Douglas J Steele - 22 Feb 2006 15:12 GMT
What do you mean by adding an autonumber to a table? Are you talking about
adding a new field to the table and making that field an Autonumber field,
or do you mean assigning the Autonumber field a value?

There shouldn't be any problem adding a new Autonumber field to an existing
table.

You shouldn't be trying to assign values to Autonumber fields.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Dear Mr. Spencer,
> How do you add autonumber to a table that already has data in it. When I try
[quoted text clipped - 53 lines]
> > >> >
> > >> > Any suggestion or recommend.  Thanks.
HaLevi - 23 Feb 2006 01:36 GMT
I have tried a number of times to add an auto number column to a table and
every time it says you cannot because there is already data in the table. If
you know a way to do it anyway , please tell me.
Signature

knuble07

> What do you mean by adding an autonumber to a table? Are you talking about
> adding a new field to the table and making that field an Autonumber field,
[quoted text clipped - 82 lines]
> > > >> >
> > > >> > Any suggestion or recommend.  Thanks.
Rick Brandt - 23 Feb 2006 02:14 GMT
> I have tried a number of times to add an auto number column to a
> table and every time it says you cannot because there is already data
> in the table. If you know a way to do it anyway , please tell me.

You would get that error if you tried to change an existing number field to an
AutoNumber, but adding a NEW AutoNumber field should be no problem.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

Larry Daugherty - 23 Feb 2006 07:55 GMT
With your table in design view, insert a row at the top of the design
form.  Give the field the name of your table followed by "ID":
MyTableID.  For type choose Autonumber.  With that row/field still
selected, click the Key icon on the toolbar above the window.  That
makes MyTableID the Primary Key of this table.  Save your table return
to table view.  You will find a value in every row of the field
MyTableID.

As for the value of an autonumber datatype, its ONLY purpose in life
is to generate unique values to serve as a surrogate Primary Key.  Any
other use of the autonumber datatype will eventually lead you into
trouble.  It is not guaranteed to be sequential.

The content of that field should never be seen nor used by a human
being.  If it is shown troubles will come.

An earlier responder obviously prefers to use natural keys.  That's
fine people should do what they feel to be best.  The problem is that
the arguments he put forward don't address the real issues.:

====================================================
"I like my PKs to have some relationship to the data.  Something
like a SSN, or a company-generated PO # or Invoice #."

SSNs are poor primary keys.  They can be changed.   So can every other
single thing in a record including a person's name. This from a fellow
with the scars of battles fought, some won and some lost.  I've been
promised on the life of first born children that a certen element of
data "will never change".  HAH!  They never let me down, the promised
unchangeable element always changed.  Company-generated PO#s can be
altered after the fact due to human error. I solved the problem to my
satisfaction by always using autonumber Primary Keys.  Never again did
I have to sweat the primary keys nor waste the time formerly spent on
resolving issues thereto.

"Autonumber fields have nothing to do with our data and are more
difficult to work with than a field of our own choosing.  Yes,
there's more chance of error when the user is expected to
enter the PK manually but in practice we see no big source of error
here. The PK actually makes sense to the user so the user is more
likely to enter it correctly."

Absolutely!  Right On!  Autonumber fields have absolutely nothing to
do with anyone's data and that is their greatest value because they're
immune to all changes to do with the user's data.  Further, if you
never show it to your users, no one will ever be after you to change
it.  Google these groups for years past and you'll see lots of posts
seeking help in managing autonumber values.  In some cases it's just
that the programmer wants things to appear all neat and tidy (that's
really worrying about neat and tidy in the wrong places, expend your
efforts on the application because that's what you get paid to do).
However, in many cases, some control freak boss has seen the "ID"
label on a control and insists that the programmer jump through hoops
and make the autonumber behave per the control freak's whim of the
day.

IMHO, if you are using Autonumber primary keys and you require a user
to enter that autonumber value **for any reason whatever**, your
application is screwed up!  By their very definition, autonumbers are
generated by Access.  When that autonumber is referenced in a Foreign
Key, Referential Integrity takes care of it for you.

======================================================

If anyone is boxed in a corner and causing her or his users to enter
autonumber values manually to make an application work, please post
back into these groups expressing your problem and asking for help
resolving it.  That's what these newsgroups are for.

HTH
Signature

-Larry-
--

> I have tried a number of times to add an auto number column to a table and
> every time it says you cannot because there is already data in the table. If
[quoted text clipped - 86 lines]
> > > > >> >
> > > > >> > Any suggestion or recommend.  Thanks.
HaLevi - 23 Feb 2006 13:42 GMT
Thanks to all who answered, especially Larry - IT WORKED!
Signature

knuble07

> With your table in design view, insert a row at the top of the design
> form.  Give the field the name of your table followed by "ID":
[quoted text clipped - 187 lines]
> > > > > >> >
> > > > > >> > Any suggestion or recommend.  Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.