Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
When to assign unique key.
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00058229
Message ID:
00059261
Views:
33
>>>>I am working on a Customer Info form and I want to assign a unique customer number when a user chooses to add a new customer. If I do anything like a CALCULATE MAX() on existing customer numbers, the record pointer moves and a TABLEUPDATE() is automatically issued.
>>>>
>>>>Any ideas on the best way to do this?
>>>
>>>MAX(), COUNT() and a few other commands move the record pointer. The best way to assign a unique key is with a procedure stored in the dbc that pulls the unique value from table that stores the next unique value for all of your tables that require a unique value. This may seem like a pain and overkill for the time being, but as your apps and tables grow, it becomes evident that this is the only way to go. So you have field that is not the primary key but needs a unique value anyway? Define it as candidate and use the same teqhnique. Tastrade contains a stored procedure and a table that does this. Another tip that has quickly become the 'right' way to do things: all primary keys should be surrogate. That is, the ser should never see them, and they should have no real world value.
>>
>>Hi Erik,
>>
>>I found the stored procedure -- NewId but I'm having a hard time finding where in the Tastrad app it is actually called. Is it just me or does anyone else find the Tastrade example a little over complicated and convaluted?
>
>
>NewID() is called called from the Default Value in the table designer.
>You need an IDS (or something) table in the DATABASE
>
>Check out the solution app that comes with VFP it has a good example of this...
>Good Luck
>Jerimi

Thanks to both you Jerimi and Erik for your replies. I've created the stored procedure in my database and created an IDS table as well. Instead of assigning the key in the fields Default Value I assign just before the TABLEUPDATE() with REPLACE Suppliernum WITH NewId(). This works great in development but when I compile to a EXE I get the error 'Program NewId does not exist'. Am I missing a particular setting to make the app look in the stored procedures? My PATH includes the data directory.
Colin Magee
Team Leader, Systems Development
Metroland Media Group Ltd.
Mississauga, Ontario, Canada

cmagee@metroland.com

Never mistake having a career with having a life.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform