Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Primary key
Message
 
 
To
28/08/1999 19:00:44
Zubair Ahmed
Al-Noor Sugar Mills Ltd
Karachi, Pakistan
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00258875
Message ID:
00258990
Views:
13
>I had problem with a table's primary key.. I create a table and select a column (character 6 width) as a primary key to elimanate for duplicate entries.. but strangley I found out duplicates entries after one month.. how it happned.... i am using visual foxpro ver 5.0
>
>one thing more.. when i drop primary key and create the one again.. it showed me error..
>
>so please help me where did i make mistake..
>

Also, do you base your primary key on a value stored in a Counters table? Or do you go to the bottom of the table ordered by the primary key to get the last used PK? The best way is to keep a record of the last PK used in a Counters table. My counters table has 3 fields -- TableName, KeyName, Kount. When I need a new PK for a specific table, I go to the record in the counters table that matches the tablename and keyname. I increment the Kount field by 1 and return that number as the next PK to use.

The danger of basing the next PK to use on the last PK in the table is deleted records. If SET DELETED ON, you could have a deleted record after the last un-deleted record. Therefore, you would be repeating the PK of the deleted record.

To find duplicate PKs, you can execute the following query:
SET DELETED OFF
Select pk_fieldname, count(pk_fieldname) as Kount from mytable ;
   group by pk_fieldname having Kount > 1 into cursor crsDups nofilter
Mark McCasland
Midlothian, TX USA
Previous
Reply
Map
View

Click here to load this message in the networking platform