Assuming the default isolation READ COMMITTED:
Code: Select all
create table t1(id int, val int)
insert into t1(1,10)
insert into t1(2,20)
insert into t1(3,30)
The table 't1' contains three accounts (id) with some money(val).
Now in Session 1
Code: Select all
isql -U vc -P vc
1> SET IMPLICIT_TRANSACTIONS ON
1> select * from t1
2> go
id val
----------- -----------
1 10
2 20
3 30
(3 rows affected)
Now take money from Account 3:
1> update t1 set val=val-30 where id=3
2> go
(1 row affected)
...and in Session 2:
Code: Select all
1> SET IMPLICIT_TRANSACTIONS ON
1> select sum(val) from t1 where id <=3
2> go
The session is blocked by Session 1's update
... and in Session 1:
Code: Select all
...transfer money to Account 1:
1> update t1 set val=val+30 where id=1
2> go
(1 row affected)
1> commit
2> go
1>
... and in Session 2
Code: Select all
Session is unblocked
-----------
30
(1 row affected)
1>
and gives an incorrect answer (should be 60)
I understand what's going on but the question is whether it's possible to fix the problem under SQL Server 2K without changing the code, or the locking works pretty much in the same way as it did under Sybase (version 10) ? Changing to SERIALIZABLE is not an option either.
The original task is about moving network devices between hubs but it can be expressed in terms of money transfer between accounts.
Thanks.
Rgds.