Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary key problem
Message
De
26/10/2001 11:29:07
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
26/10/2001 11:19:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00573665
Message ID:
00573674
Vues:
25
One frequent solution is to have a filtered index (filter on "not deleted()").

Since I think this isn't allowed for a primary key, you can change the key value at the moment you delete it. For instance, at the moment you delete a record, set the PK value = str(-recno()). This should ensure uniqueness.

HTH, Hilmar.

>Hi,
>
>I've got a problem with primary keys. They look like "00001", "00002", etc. Anyways I have run into a situation where I have to reuse them. So for example, if the table contains five records, "00001", "00002", "00003", "00004", "00005" and the user deletes "00003" I wind up with "00001", "00002", "00004", "00005". I have to change it to "00001", "00002", "00003" (used to be 00004), "00004 (used to be 00005). I do this with the following code. The order is set to "tid" which is the Primary key.
>
>scan rest
>     replace tid with padl(str(val(tid)-1),5,"0")
>endscan
>
>
>I get a uniqueness of primary key error. I have set deleted on. If I do a pack it works, but I can't do that when the users are using it. Any ideas on how to solve the problem without making the primary key not primary? I am working with a treeview active x control and I am using this as a way to identify an item. The treeview source is a table. When the user deletes one, it is deleted from the table. Then I clear the treeview and add all the items all over again. Maybe there is a better way of doing this? It seemed like overkill when I did it, but can't think of any other way as I need to have the primary key matching the key for that item created by foxPro when the treeview is created.
>
>Thanks!
>Chris
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform