I think you may have some misconceptions about autonumbers.
You don't skip any records, but records may or may not be sequentially
numbered without gaps.
For starters, autonumber fields do not have to be sequential by 1. You can
set them as random, so that random numbers are used and you can set the
increment to some value other than 1, so they may be numbered 10, 15, 20, 25,
etc.
You can guarantee there will almost always be gaps in the numbering. That is
because the number is assigned as soon as the first character of a record is
entered into the record, but if the record is undone before it is saved, the
record is discarded, but the number is not reused. The same goes for
deleting records. If you delete a record, its number is not reused.
But, even with all that said, autonumbers should have no meaning in a
relational database. They should never be exposed to a user. Their
intended use is only as a surrogate primary key. It is also useful for using
in child tables as a foreign key to the parent.
As Jeff said, anytime someone says autonumber, there is a discussion on
whether they should ever be used or not. I am in favor of them. My
reasoning is that it easily makes a unique primary key. If you have to have
multiple fields to create a unique value, particularly if they are not of the
same data type, it takes more space in the database and to some degree
degrades performance. I have seen one instance where a 5 field key was used
that had a text field, a date field, and 3 long integer fields to make up a
primary key. It wasn't too bad in Jet, but when we upsized that app to SQL
Sever, updates and deletes got really slow. The extra time as in rebuilding
indexes. It also means you have to have all those fields in any child
records or build your own unique value to relate the child to the parent.
But, that is just my opinion.
So, I don't see how that is an audit issue. It would be no different than a
natural key. How will you know if a record was deleted? If you need true
record level auditing, you need to implement auditing in your application to
track who added a record and when, every change to every record with who and
when and if a record is deleted, who and when. Otherwise, there really is no
way to audit a database other than comparing to a backup copy and that
doesn't give you any real information on how the changes happened.
This is of course considerable overhead, but for regulated or sensitive data
applications, it is the better way to do it.
So the short of it is, there is no more risk using Autonumbers than there is
using natural keys.
--
Dave Hargis, Microsoft Access MVP
acss said:
I have read many postings of the tendancy/possibility of skipping records and
for this reason i do not have any autonumber fields. It would have been
better in my DB design to utilize the autonumber for one of my tables but i
did not want to take that chance.
:
Just out of curiosity, what auditing concern prevents the use of autonumbers?
--
Dave Hargis, Microsoft Access MVP
:
I just tried making both fields as primary and it worked fine since it
allowed the same invoice with a different vendor number. I can not use auto
number due to auditing concerns so this is what i needed. Thank you
:
It sounds like you are describing a real-world situation in which
[InvoiceNumber] is NOT unique. Primary keys MUST be unique.
Therefore, you can't use [InvoiceNumber] as a primary key.
But if [InvoiceNumber] and [Vendor] is ALWAYS unique, you could have a
two-field primary key...
(this is a starting point for the discussion/argument about using Autonumber
primary keys -- "arbitrary" -- rather than "natural" keys).
Good luck!
Regards
Jeff Boyce
Microsoft Office/Access MVP
I have an invoice DB and the primary key field is for the invoice number
which is unique and should not be duplicated. I have just received
duplicate
invoices from differnt vendors so how does one work around this scenario?
invoiceID field=primary key unique
vendor number field=unique