Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
NextID for SQL syntax
What is the correct way (record locking,etc.) to make a "NextID" function for sql? I am using the following, but can forsee problems if tons of users bang on this thing at the same time:
function NextID(pTable)
select lastval from dbsequences into array laNum where tablename = pTable
laNum[1] = laNum[1] + 1
update dbsequences set lastval = laNum[1] where tablename = pTable
RETURN(lnNum[1])
This type of thing works fine for few users. My question is what happens when two users hit this thing at about the same time? Both will get the same number and that will cause a big problem. Somehow the record should be locked,updated,unlocked to prevent this. I know how to do it using normal VFP commands: locate for..., lock(), replace ,unlock(). etc., etc. I just can't figure out how it's done in the SQL world.
- Gary
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