sql server 2008 - SQL Basic Concurrency -


insert t1 (xfield) select 7 xfield (select count(*) t1) = 0 

basically, if million users run @ same time, there ever end being more 1 row in t1?

thread a: select count(*) t1: 0 thread b: select count(*) t1: 0 thread a: insert t1... thread b: insert t1... 

or guaranteed never happen, because it's 1 statement?

if isn't safe, this?

table t2 (gonorth , gosouth must never both 1):

id      gonorth   gosouth 1       0         0 

then happens:

user a: update t2 set gonorth = 1 gosouth = 0 user b: update t2 set gosouth = 1 gonorth = 0  thread a: find rows gosouth = 0 thread b: find rows gonorth = 0 thread a: found row gosouth = 0 thread b: found row gonorth = 0 thread a: setting gonorth = 1 located row thread b: setting gosouth = 1 located row 

and result:

id      gonorth   gosouth 1       1         1 

what rules can happen @ same time , can't?

my database engine "microsoft sql server 2008 r2 (sp2)".

no. it's written single statement, , therefore rules of sql provide entire statement atomic.

however, there caveats here. first of all, mean creating quite large number of locks, point table becomes unavailable until query completed. in other words, in order guarantee safety, you'd throwing away concurrency. other caveat holds default isolation level. weaker isolation level may allow query run without creating appropriate locks. weak isolation level might allow ignore locks.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -