Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Identity question
Message
From
07/07/2000 21:22:21
 
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00388555
Message ID:
00389769
Views:
30
Agreed, the place where I have used it gets very little use maybe every few days.

One idea I had where this technique 'may' work every time which I have not tested or researched yet, is to do the insert through a stored procedure. (Pass all parameters to be inserted into SP). In the stored procedure, after the insert is done find the MAX(identity) and return this as an output parameter to the calling procedure. What I don't know is how SQL handles this behind the scenes. Will SQL execute and complete the entire SP, before any further inserts are allowed?

Thoughts or comments on this idea?

John

>>I have used the code similar to the following to get what you are asking for. Depending on your circumstances and number of users it may work for you. This line should be executed immediately after the insert.
>>
>>SELECT MAX(identitycolumn) FROM tableA
>>
>
>I would not recommend using this technique unless there was an exclusive lock on the table between the time that the query is issued and the time that the new row (with the MAX()+1 ID) is written. In a database with a lot of concurrency, it is more that possible for a new row to be written within that period, especially if you're making a trip back to the client with the information.
>
>-Mike
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform