473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Using an auto-number as a primary key

At http://www.blueclaw-db.com/tips_tricks.htm I came across a section
which is included below and was hoping for some comment on the
article.

--------------

Almost never use this auto-number field as the primary key of the
table.

If you are thinking of hiring an Access programmer or consultant ask
to see a screen shot of a relationship diagram from an Access database
he/she has built. If you see an auto-number ID field in bold then ask
them 'what will prevent two records with the same data getting into
this table?' If they can't give you a good answer then don't hire
them.
----------------------------

Geoff
Nov 12 '05 #1
5 4505
DFS
Geoff,

I didn't read the whole article, but what you quoted is a simplistic
statement made by someone with no knowledge of database design. What will
prevent two records with the same data from being added to the table is a
unique index on whichever fields constitute uniqueness. This index is
unrelated to the autonumber primary key field.

Many, if not most, databases use an automatically generated integer value
for a primary key in some or most tables. I can't say they're appropriate
in every case, but if I see a database using only semantic keys (these are
primary keys set on fields with system data in them: last name, first name,
job title, etc) it's not hard to find tables where updating the data becomes
difficult because of the primary key structure.

Thinking about my systems, I use a combination of semantic and non-semantic
primary keys. It just depends: on the system, how many tables (if you have
to join 8 tables to get a query with meaningful data in it you may want to
stay away from non-semantic keys), how much data, etc.
Semantic key example:

CodeTable
CodeID

CategoryTable
CategoryID

AirCarriersTable
AirCarrierID

PassengersTable
PassengerID
PassengerName

TransactionTable
CodeID
CategoryID
AirCarrierID
PassengerID

In this case, you end up with a transaction table full of just ID numbers,
and you have to create a query joining all the tables to see meaningful
data.

Here's a discussion on primary keys
http://www.4square.net/papers/NonSemanticKeys.html in which the author
argues for ONLY an autonumber type (non-semantic) primary key.

"Geoff Cayzer" <ca****@optusnet.com.au> wrote in message
news:22*************************@posting.google.co m...
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section
which is included below and was hoping for some comment on the
article.

--------------

Almost never use this auto-number field as the primary key of the
table.

If you are thinking of hiring an Access programmer or consultant ask
to see a screen shot of a relationship diagram from an Access database
he/she has built. If you see an auto-number ID field in bold then ask
them 'what will prevent two records with the same data getting into
this table?' If they can't give you a good answer then don't hire
them.
----------------------------

Geoff

Nov 12 '05 #2
"Geoff Cayzer" <ca****@optusnet.com.au> wrote in message
news:22*************************@posting.google.co m...
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section
which is included below and was hoping for some comment on the
article.

--------------

Almost never use this auto-number field as the primary key of the
table.

If you are thinking of hiring an Access programmer or consultant ask
to see a screen shot of a relationship diagram from an Access database
he/she has built. If you see an auto-number ID field in bold then ask
them 'what will prevent two records with the same data getting into
this table?' If they can't give you a good answer then don't hire
them.
----------------------------

Geoff


Personally, I can't agree with that statement. An auto-number is often a
suitable primary key. The principal function of the primary key is not to
prevent data duplication, though it sometimes does this, but rather, unique
identification of every record in a table. Auto-number is an easy way to
generate unique values.
Nov 12 '05 #3
"DFS" <no******@nospam.com> wrote in message
news:vt************@corp.supernews.com...
Geoff,

I didn't read the whole article, but what you quoted is a simplistic
statement made by someone with no knowledge of database design. What will
prevent two records with the same data from being added to the table is a
unique index on whichever fields constitute uniqueness. This index is
unrelated to the autonumber primary key field.
IMO, what you say is correct, however, concluding that the author of that
statement has "no knowledge of database design", based on a single small
error, is unfair. And probably not correct.
Many, if not most, databases use an automatically generated integer value
for a primary key in some or most tables. I can't say they're appropriate
in every case, but if I see a database using only semantic keys (these are
primary keys set on fields with system data in them: last name, first name, job title, etc) it's not hard to find tables where updating the data becomes difficult because of the primary key structure.

Thinking about my systems, I use a combination of semantic and non-semantic primary keys. It just depends: on the system, how many tables (if you have to join 8 tables to get a query with meaningful data in it you may want to
stay away from non-semantic keys), how much data, etc.
Semantic key example:

CodeTable
CodeID

CategoryTable
CategoryID

AirCarriersTable
AirCarrierID

PassengersTable
PassengerID
PassengerName

TransactionTable
CodeID
CategoryID
AirCarrierID
PassengerID

In this case, you end up with a transaction table full of just ID numbers,
and you have to create a query joining all the tables to see meaningful
data.

Here's a discussion on primary keys
http://www.4square.net/papers/NonSemanticKeys.html in which the author
argues for ONLY an autonumber type (non-semantic) primary key.

"Geoff Cayzer" <ca****@optusnet.com.au> wrote in message
news:22*************************@posting.google.co m...
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section
which is included below and was hoping for some comment on the
article.

--------------

Almost never use this auto-number field as the primary key of the
table.

If you are thinking of hiring an Access programmer or consultant ask
to see a screen shot of a relationship diagram from an Access database
he/she has built. If you see an auto-number ID field in bold then ask
them 'what will prevent two records with the same data getting into
this table?' If they can't give you a good answer then don't hire
them.
----------------------------

Geoff


Nov 12 '05 #4
DFS
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:yu**********************@newssvr28.news.prodi gy.com...
"DFS" <no******@nospam.com> wrote in message
news:vt************@corp.supernews.com...
Geoff,

I didn't read the whole article, but what you quoted is a simplistic
statement made by someone with no knowledge of database design. What will prevent two records with the same data from being added to the table is a unique index on whichever fields constitute uniqueness. This index is
unrelated to the autonumber primary key field.


IMO, what you say is correct, however, concluding that the author of that
statement has "no knowledge of database design", based on a single small
error, is unfair. And probably not correct.


True - maybe a little unfair and incorrect.

As I said, I didn't read the article from which that quote came, but it's
definitely not a small error. It's a huge error, which clearly demonstrates
LACK OF (previously I said NO) knowledge of database design. Perusing the
article http://www.blueclaw-db.com/tips_tricks.htm I see the author knows
more than I expected, but still makes some odd and incorrect statements,
such as

"Again, never use the Unique Numeric ID (auto-number) for the primary key
unless it is used as data in other areas of your business (examples would be
Serial_Number_ID, PO_Number_ID)."

I hope you're not the author, Randy.


Many, if not most, databases use an automatically generated integer value for a primary key in some or most tables. I can't say they're appropriate in every case, but if I see a database using only semantic keys (these are primary keys set on fields with system data in them: last name, first

name,
job title, etc) it's not hard to find tables where updating the data

becomes
difficult because of the primary key structure.

Thinking about my systems, I use a combination of semantic and

non-semantic
primary keys. It just depends: on the system, how many tables (if you

have
to join 8 tables to get a query with meaningful data in it you may want to stay away from non-semantic keys), how much data, etc.
Semantic key example:

CodeTable
CodeID

CategoryTable
CategoryID

AirCarriersTable
AirCarrierID

PassengersTable
PassengerID
PassengerName

TransactionTable
CodeID
CategoryID
AirCarrierID
PassengerID

In this case, you end up with a transaction table full of just ID numbers, and you have to create a query joining all the tables to see meaningful
data.

Here's a discussion on primary keys
http://www.4square.net/papers/NonSemanticKeys.html in which the author
argues for ONLY an autonumber type (non-semantic) primary key.

"Geoff Cayzer" <ca****@optusnet.com.au> wrote in message
news:22*************************@posting.google.co m...
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section
which is included below and was hoping for some comment on the
article.

--------------

Almost never use this auto-number field as the primary key of the
table.

If you are thinking of hiring an Access programmer or consultant ask
to see a screen shot of a relationship diagram from an Access database
he/she has built. If you see an auto-number ID field in bold then ask
them 'what will prevent two records with the same data getting into
this table?' If they can't give you a good answer then don't hire
them.
----------------------------

Geoff



Nov 12 '05 #5

"DFS" <no******@nospam.com> wrote in message
news:vt************@corp.supernews.com...
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:yu**********************@newssvr28.news.prodi gy.com...
"DFS" <no******@nospam.com> wrote in message
news:vt************@corp.supernews.com...
Geoff,

I didn't read the whole article, but what you quoted is a simplistic
statement made by someone with no knowledge of database design. What will prevent two records with the same data from being added to the table
is
a unique index on whichever fields constitute uniqueness. This index is
unrelated to the autonumber primary key field.
IMO, what you say is correct, however, concluding that the author of that statement has "no knowledge of database design", based on a single small
error, is unfair. And probably not correct.


True - maybe a little unfair and incorrect.

As I said, I didn't read the article from which that quote came, but it's
definitely not a small error. It's a huge error, which clearly

demonstrates LACK OF (previously I said NO) knowledge of database design. Perusing the
article http://www.blueclaw-db.com/tips_tricks.htm I see the author knows
more than I expected, but still makes some odd and incorrect statements,
such as

"Again, never use the Unique Numeric ID (auto-number) for the primary key
unless it is used as data in other areas of your business (examples would be Serial_Number_ID, PO_Number_ID)."

I hope you're not the author, Randy.


No, definitely not. I make no claims to being an expert. I agree as well,
however, that second statement above is also poor advice. Perhaps a more
serious error than the earlier one. I believe that auto-number keys should
never, under any circumstances, be used to contain data. So called "smart
keys" are very poor design.
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
0
by: Matt Kruse | last post by:
I'm making changes to an intranet web app that uses only IE6 as the browser. It makes use of CSS expressions for dynamic positioning and other tricks, and it works quite well. My question is:...
13
by: Mike | last post by:
We are using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"...
22
by: Bradley | last post by:
Has anyone else noticed this problem? I converted the back-end to A2000 and the performance problem was fixed. We supply a 97 and 2000 version of our software so we kept the backend in A97 to make...
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
2
by: abhishek11 | last post by:
Hi All I have a box with shadow around it. Now i have to render a red bar inside it at the top. This red bar should expand when the box expands but this is not happening in mozilla. Here is the...
0
by: rgebbie | last post by:
I have seen some previous posts regarding problems building Perl on AIX with gcc. Unfortunately, none of the posts produced any answers to the problem. I am also having similar problems, and I hope...
13
by: Javad | last post by:
Hello I know that I should get the information of windows internet connections by using "rasapi32.dll" library, and I also have some sample codes, but I can't make them work. My exact need is to...
10
by: =?Utf-8?B?TWF0dA==?= | last post by:
I am using the following code to connect to and download files from an ftp server, but the Symantec anti-virus software on some of my customers machines tells them that their computers are...
3
by: gudiya | last post by:
hi, My code works but i am missing the first 2 characters of file name. Any idea why???? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.