>Hi All,
>
>This is an interesting thread. Sorry for perhaps being naive :) but if the purpose of generating a primary key is to have an absolutely unique key for each record in a table then surely a quicker solution is to use a function which guarantees uniqueness *without* even needing to check if the key already exists. For example
>
>(local hard disk serial number) + Substr( Sys(2015), 3, 10 )
>
>The hard disk serial number guarantees uniqueness over a multiuser environment and, according to the VFP help, the sys(2015) generates unique strings within the same millisecond. Wouldnt this work?
Probably yes, but it would be a big character field. Also you should retrieve hard disk serial number, which is not a trivial task. Craig solution is much simpler, it works in multi-user environment and you use integer field, which is 4 bytes only.
If it's not broken, fix it until it is.
My Blog