472,378 Members | 1,443 Online

# Will "Random AutoNumber" reuse deleted values?

A KB article
"http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells
that the maximum number of records that a table may hold if the PRIMARY
key data type is set to AUTONUMBER is 4,294,967,295.

Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber.

Suppose an application
(a) successfully INSERTS "X" records, then
(b) successfully DELETES "Y" records (X >= Y), then
(c) successfully INSERTS "Z" records to a table to the capacity limit
of that primary key (i.e. insertion of a "Z+1"th record would have
caused a "duplicate primary key" condition).

Suppose there are no hardware or software failures and unlimited
HDD/RAM space.

Is it guaranteed that (X-Y+Z) = 4,294,967,295 ?
I.e. will Random AutoNumber reuse all "holes" left after deletion of Y
records?

--

Nov 13 '05 #1
4 5016
It's random: there's no guarantee that an attempt won't be made to reuse any
number.

Since there's a 2 GB limit on an MDB, I rather suspect you'll hit that limit
long before you use up all of the autonumber values.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele

"yf" <yf******@gmail.com> wrote in message
A KB article
"http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells
that the maximum number of records that a table may hold if the PRIMARY
key data type is set to AUTONUMBER is 4,294,967,295.

Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber.

Suppose an application
(a) successfully INSERTS "X" records, then
(b) successfully DELETES "Y" records (X >= Y), then
(c) successfully INSERTS "Z" records to a table to the capacity limit
of that primary key (i.e. insertion of a "Z+1"th record would have
caused a "duplicate primary key" condition).

Suppose there are no hardware or software failures and unlimited
HDD/RAM space.

Is it guaranteed that (X-Y+Z) = 4,294,967,295 ?
I.e. will Random AutoNumber reuse all "holes" left after deletion of Y
records?

--

Nov 13 '05 #2
{add 10,000,000 records, delete 9,000,000 records} repeated daily.
Looks like after 429 days I'll exsaust all 4,294,967,295 Random
AutoNumber unique values and will start occasionally (with a
probability 10%) getting a "duplicate primary key"?

Nov 13 '05 #3
yf wrote:
{add 10,000,000 records, delete 9,000,000 records} repeated daily.
Looks like after 429 days I'll exsaust all 4,294,967,295 Random
AutoNumber unique values and will start occasionally (with a
probability 10%) getting a "duplicate primary key"?

It would need compactinmg every day then :-)

BTW for adding 1,000,000 records a day, are you sure you want to use
something as lightweight as Access/Jet?

--
This sig left intentionally blank
Nov 13 '05 #4
Once a record is deleted, its Autonumber value can be reused. Even with a
standard incremental Autonumber, a value can be reused if the highest-numbered
value is deleted, then the database is compacted. For this reason, no kind of
Autonumber is suitable for use as a logical key.

If, however, the Autonumber value will only be used as a surrogate key within
the database app and will never be used as an external refrence, and if the
database makes good use of enforced referential integrity rules, there should
be no consequences to possible reuse of previously deleted Autonumber values.

So - you may frequently want to use Autonumer keys as surrogate keys, but use
another technique other than autonumber to generate unique logical keys. A
good logical key might be a string representation of a new GUID obtained using
a Windows API call. Another option I rather like for building unique logical
keys is CCur(Format(Now,"yyyymmdd") & Format(Timer*10,"000000.00") &
Format(Rnd*100,"00")), making sure to call Randomize at some point prior to
executing this code. If, for some reason, you'd like make sure records will
sort randomly using the logical key, change that formula to
CCur(Format(Rnd*100,"00") & Format(Timer*1000,"00000000") &
Format(Now,"ddmm.yyyy")).

If you need more assurance that the random number part won't be duplicated
during the same millisecond, you can replace the call to Rnd with a call to a
custom non-repeating hash procedure and seed its initial counter with a random
value using Rnd. An easy hash (though not very random if that matters) is to
count from 1 and XOR the counter value with the random seed. To be fancier,
you could use modulus multiplication or exponentiation, though that can be
tricky in VB/VBA.

On 6 Dec 2004 13:16:43 -0800, "yf" <yf******@gmail.com> wrote:
A KB article
"http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells
that the maximum number of records that a table may hold if the PRIMARY
key data type is set to AUTONUMBER is 4,294,967,295.

Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber.

Suppose an application
(a) successfully INSERTS "X" records, then
(b) successfully DELETES "Y" records (X >= Y), then
(c) successfully INSERTS "Z" records to a table to the capacity limit
of that primary key (i.e. insertion of a "Z+1"th record would have
caused a "duplicate primary key" condition).

Suppose there are no hardware or software failures and unlimited
HDD/RAM space.

Is it guaranteed that (X-Y+Z) = 4,294,967,295 ?
I.e. will Random AutoNumber reuse all "holes" left after deletion of Y
records?

Nov 13 '05 #5

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