Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with primary key.
Message
From
01/11/2002 12:57:45
 
 
To
01/11/2002 07:54:08
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00717718
Message ID:
00717921
Views:
15
I had the same problem and there are a few different solutions.

Solution 1. Your primary key needs to have a filter placed on it. !deleted() (yuck)

Solution 2. Before you determine the highest number in the table SET DELETED OFF add the new record and SET DELETED ON when done (poor design!!!!)

Solution 3. Create a stored procedure that will automatically create a unique key (AutoIncrement). There was a posting on here about storing the key in a table.


e.g. Create a table with Table C(30), nKey I

In the Default portion of the database container e.g. Names.LastName DEFAULT = GetKey("Names")

The stored procedure will:
1. lock the new table
2. find the Names record
3. increment the nKey field (nOldKey = nKey) (nKey = nKey + 1)
4. unlock the file
5. return nOldKey

This is a little complicate to explain but, the MAX(Names.ID) will always be 1 less than the ID stored in the new table.


Solution 3 is the best solution!!!!
Gordon de Rouyan
DC&G Consulting
Edmonton, Alberta
Email: derouyag@shaw.ca
Previous
Reply
Map
View

Click here to load this message in the networking platform