Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NextID for SQL syntax
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00506014
Message ID:
00506068
Views:
18
Any reason you're not using an IDENTITY column instead?

>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
Insanity: Doing the same thing over and over and expecting different results.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform