Sounds like a great idea. Just to confirm, try to lock the record in the reference table, right?
>Tell your boss that his method will not work with buffered tables, because, the record number of a new record will be negative.
>
>Your method will not work also in a multiuser scenario, because 2 users adding a record at the same time will generate the same key.
>
>The best approach, IMHO, is to use a reference table that contain 2 fields: TableName and NextKey. When adding a new record, you search this table for the table name. Then you try to lock the record. If you succeed, you take the value (this will be your key), you increment the value by 1 and you unlock the record. If you do not succeed, you retry until success, because the record should be locked only for a fraction of a second at a time.
>
>HTH
>I'm looking for different ways people assign unique keys in multi user environments. My boss would like to use the record number, which sounds like a bad idea to me given that we would never be able to pack the table among other issues. Do we need to get more sophisticated than setting the order to the right index and doing:
>>GO BOTT
>>nNewID=myTable.key+1
>>INSERT INTO myTable (key) VALUES(nNewID)
>>
>>Would it make sense to have a property hold the next value and put code in the access method to encapsulate the process? Thanks for any feedback on this basic task.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement