SQL Server : incrementing non identity int column by procedure call -


i have column in db table has increment when let's item selected. can selected parallel , records has start 0. solution increment value db procedure, can sure first procedure manages increment value before procedure want load value increment? mean:

t0 value 10 t1 procedure1 valuetoinc = value t2 procedure2 valuetoinc = value t3 procedure1 valuetoinc ++ t4 procedure2 valuetoinc ++ t5 value = 11 t6 value = 11 

value written procedure1 11 procedure2 11 (need secure 12 there).

i have checked identity (property) , sequence (transact-sql) nothing seems suitable me.

edit

what i´m trying solve have console application - tcp server , mssql database, have user table. each time single user wants login, have increment users logincount field. parallelization here should not possible or manageable code, know, told me have hande parallel acces database, not use update query. have job interview project...

i wanted make understanding easier first explanation, won´t work.

you can use

update users set logincount = isnull(logincount,0) + 1 userid = @userid 

this entirely safe under conditions of concurrency.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -