Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Algorithm for generating unique value for the 6 char fie
Message
 
 
À
04/05/2001 13:52:50
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00503649
Message ID:
00503681
Vues:
28
Hi Walter,

Actually, I just thought about simple approach. Say, I set up the default value to be "NEWCOD". When user adds a new record, it automatically set focus to this field. The user will change it then. I have a mechanism for checking uniqueness built in the textbox. Of course, it he/she save this value, this problem re-appear. But I hope I'll never experience this situation (the user should be smart enough :). I can even show a message: "Change this code or you'll be fired!" :) (just joshing...)

>HI Nadya
>
>How about
>
>BINTOC(RAND(-1)*2^31-1)+RIGHT(BINTOC(RAND()*2^16),2)
>
>This take full advantage of the 6 bytes of the character field. However because of code pages, it might be wise to change the field to Character (binary). Of course there is a chance that the algorithm will create duplicate keys, so to be sure, you'll have to take care of such an event.
>
>Walter,
>
>
>>Hi everybody,
>>
>>I have a table, there field Code (Character 6) is made PK. This table contains one blank record (this is by design). Now, each time I'm issuing append blank, I get an Error "Uniqueness of indexes is violated". I'm thinking about adding a default value for this field, but I don't want to use NextID table approach, because this database doen't have a NextID table and I don't want to change it.
>>Therefore I'm seeking for the idea of a function, which will generate Unique ID automatically (Char 6).
>>
>>Or may be you have other ideas? Simple way, which was suggested by my manager, just make this index to be regular and deal this checking on the form level. I disagree, because our data is not secure enough, so if somebody will edit this table directly, there is a chance for adding duplicates.
>>
>>What do you think? I know, it's not recommended to use character PK (meangful), but this table was designed long time ago and I don't want to change it.
>>
>>Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform