Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get the last identity value for a table?
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01421835
Message ID:
01422204
Views:
60
Dmitry,

If several users are doing this activity I see lots of deadlocks in your future. You need to rethink this design because it's fairly unfriendly to the way SQL backends work.

>Let me explain more of what I am doing and why scope_identity() may not be applicable in my case.
>
>I have a generic routine where an array of one or more (easily could be 100) rows is created. Each row of the array has an expression, either UPDATE or INSERT. The method that receives this array scan through the rows and executes each command (being UPDATE or INSERT). (And of course I use TRANSACTION so that if any one command failes it will be ROLLed back). Some of the UPDATE commands need to have a value of IDENTITY (PK) from some other INSERT command. So for these cases the UPDATE expression has a "place holder" string in a form of a call to a method that gets the IDENTIFY from a different table and then the program replaces/inserts this value into the UPDATE expression. Since there is difficult to predict in which order the rows of the array will be processed (that is, there could be an INSERT between INSERT that I need to get the IDENTITY value and the UPDATE where this value is necessary, I am choosing to use INDENT_CURRENT which gives me the value. I have not tested the entire routine yet; will be doing it this week.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform