Wiki Home

Unique Key Generation

Namespace: Wiki
What are the tried and true methods for generating keys?

See also: Primary Key Data Types

Auto Incrementing Field
High Low Key Generation

Other Issues

Distributed Assignment
If you have disconnected locations of data entry, like laptops, keys need to be assigned and either reassigned when the data is added to the "master" database, or some method of making sure that as keys are generated, they are still unique. the guid is one solution. Pre allocating keys in batches is another.

Location of the procedures to generate keys
For VFP stored procedures in the dbc is a natural place to put this routine. There are disadvantages to stored procedures: odbc drivers don't fully support the VFP command set (or so I'v heard), harder to update without taking down the system.
MiddleTier components, accessible via COM, are another candidate location.

Running out of Key Values
What policies do real developers adopt when they run out of unused identifiers?

I was faced with the reality that in 20 hours, my client would enter timecard 1,000,000. You guessed it, 6 digit key field. After some wild ideas, we set the counter to -99,999 and bought ourselves a few months. We later added a few chars to the field. -- ?CFK
In one instance I was using character values and switched from base 10 to base 16--employing A-F above 0-9. -- Randy P

Our order system was just like Randy P's except I went to base 36 using 0-9 then A-Z. Sadly we will be replacing this system some time this year, I'd hoped to see it run long enough to produce reams of orders with 4 letter words in the keys.
See Also Base X Mk Key Primary Key Data Types
Contributors: Carl Karsten, Randy Pearson, John Koziol, Christof Wollenhaupt, Bob Archer, Dafydd Rees
Category Data Category Principles And Guidelines Category Key Fields Category Object IDs
( Topic last updated: 2006.01.26 02:45:08 PM )