Article ID: 106708
Article Last Modified on 2/12/2007
FUNCTION ukey
PARAMETER lenkey
IF PARAMETERS()=0
lenkey=8
ENDIF
IF lenkey=1
RETURN RIGHT(SYS(3),1)
ENDIF
len1=FLOOR(lenkey/2)
len2=lenkey-len1
key1= RIGHT(SYS(3),len1)
key2= RIGHT(SYS(2015),len2)
RETURN key1+key2
Theoretically, this method allows more possible keys than FoxPro can store
records, without a duplicate; however, there is the possibility of
duplication because of the cyclic nature of the algorithm (which is based
on the system time and date).
goodkey=.F.
DO WHILE !goodkey
newkey= UKEY()
SELECT KEYFIELD from MYDATA WHERE KEYFIELD=newkey
goodkey=IIF(_TALLY=0,.T.,.F.)
ENDDO
This method will slow down as the data grows. However, this method is adequate for tables with less than 16 million records. For larger tables, use a
key length that is greater than 8.269387 How to obtain a GUID in Visual FoxPro
Additional query words: VFoxWin FoxMac FoxDos FoxWin 2.50 2.50a 2.50b 2.50c 2.60 unique key avoid duplicate record
Keywords: kbcode KB106708