BruceM said:
ID already makes it unique. That's good enough for me.
Let me give you a real life example I encountered just last week. I am
converting a database table with FirstName and LastName columns plus
the ubiquitous single column PK incrementing INTEGER autonumber column
named ID. The autonumber takes care of the duplicates so there could
happily be two 'Jean Dupont's in the database. However, a problem
arises when data arrives via an email and a procedure named (something
like) GetIDUsingName kicks in, which queries the database using
LastName = 'Dupont' and FirstName = 'Jean' and takes the first row from
the resulting recordset. No problem for me: the client's instruction is
to do a straight port, bugs and all and the autonumber PK actually
makes this bizarre function highly predictable in practice. But it
makes me wonder if that duplicate-breaking autonumber is actually a
solution for anything ...
What if I want to order the information in some other way. If there is
validity to your statements about physical order on the disk it seems to me
it would only apply to one way of looking at the data (sorted alphabetically
by name). What happens if I want to sort by age or by gender, or
whatever?
You should always use an ORDER BY. My point is, when the physical order
happens to coincide with the requested ORDER BY you will get a
performance gain. Obviously you can have only one physical order so you
should choose wisely e.g. the order you most frequent request in your
ORDER BY statements. By choosing your autonumber for the physical
order, you never get the performance benefit; looked at another way,
you are always taking a performance hit.
ORDER BY is not the prime example, though. GROUP BY and BETWEEN are
more significant. That's why I used that example of, 'grab me all the
phone numbers of people whose last name begins with A'. If the required
data rows are already next to each other, as it is in a paper copy
telephone directory, the performance advantage is clear (remember the
BETWEEN and GROUP BY are applied to the rowset early on, whereas ORDER
BY is only applied at the end of the process).
I know of only one way of choosing the physical order in my Jet table
and that is to use the PRIMARY KEY functionality and ensure the file is
regularly compacted. If I want a column that cannot be null and must
contain unique values, but would not be the best choice for the
physical order of the table, I can use NOT NULL with either a UNQIUE
CONSTRAINT or a UNIQUE INDEX.
I use a PK because it is the established method. I am interested in using
Access to meet my needs, and feel no compulsion to first reinvent the wheel.
PK works, so I use it. I don't care about physical order on the disk or
clustered indexes or anything of that sort. If I saw some objective
benchmark data showing me that my databases are experiencing a performance
hit because of my use of autonumber PKs I would rethink what I am
doing
But you are advising others to use autonumber PKs, thus propagating bad
advice.
I guess my methodology is to try to find the best way of doing
something. I can use logic to determine that a table in physical order
of its 'prime usage' will have a performance advantage so I will go
with this approach unless there is another issue e.g. doing so would
make my schema more difficult to maintain.
With the greatest respect, your approach seems to be more like, 'Well,
it works for me and doesn't run like a dog so I won't change my ways
until someone reputable tells me I should.'
But thank you, as ever, for listening.
Jamie.
--