sql - How to get Unique Value from a table for different sessions -
I have a process that creates Example: Account ID :: MG110000021 (110000021, we are getting from the MaxAccountID table) For example: We received Therefore each session will receive This does not solve my problem, however, we also account ID for the same (duplicate) different sessions. Account ID value. Maybe it will help The value will be directly back. unique account ID while
Accounts When creating
Maximum Account ID is stored in another table (
Table :: MaxAccountID ).
TABLOCKX for unique code id Because the same SP is being called during a fraction of a second in many sessions.
TABLOCKX with the unique
account id .
SELECT @OutPutID = Account ID from MaxAccountID (TABLOCKX) UPDATE MAXAccountID SET AccountID = AccountID +1
Start from the BEGIN transfer EXEC GetMax_AccountID @OutPutID account INFO included (------------ COMMIT TRANSACTION Finally start the catch rollback transfer end capture
GetMax_AccountID are included in the form of output para as output para
SELECT @OutPutID = AccountAd, from MaxAccountID With (TABLOCKX) UPDATE MAXAccountID SET AccountID = AccountID +1
UPIDATE MAXID_Task SET ID = ID + 1 OUTPUT If you need it in the variable:
DECLARE @Result TABLE (ID int) Update MAXID_Task SET ID = ID + 1 OUTPUT In the deleted I, select the @ result @OutPutID = result @ id
Comments
Post a Comment