ismotuononen
Programmer
- Jan 1, 2009
- 6
is it possibly to execute next scenarion with sqlserver?
and if it is possible, how?
I have tried "Read commited snapshot", nolock, readpast and all kind of combinations, but nothing seems to work properly.
both sessions runs same time with separed programs and both session have "autocommit off" mode
What I want to do:
SESSION 1:
create table a(a varchar(2));
insert into a values('1');
insert into a values('2');
commit;
select * from a;
A
-
1
2
2 row(s)
SESSION 2:
select * from a;
A
-
1
2
2 row(s)
SESSION 1:
update a set a='3' where a='1';
Processed: 1
SESSION 2:
update a set a='4' where a='2';
Processed: 1
SESSION 1:
select * from a;
A
-
3
2
2 row(s)
SESSION 2:
select * from a;
A
-
1
4
2 row(s)
# so both session saw only own updates and committed data.
# and both sessions can do those updates, they don't lock each other, because they don't handle same rows.
SESSION 2:
commit;
SESSION 1:
select * from a;
A
-
3
4
2 row(s)
SESSION 2:
select * from a;
A
-
1
4
2 row(s)
SESSION 1:
commit;
SESSION 2:
select * from a;
A
-
3
4
2 row(s)
# so only after COMMIT data chances.
but befoce commit both sessions can read committed data and own updates.
BUT if sessions try to update same row, then session must lock (or give exception)
the real problem aren't this simple, but this scenario shows whats is the problem. that scenario works all other databases, but I can't get it working in sqlserver.
I am using:
Microsoft SQL Server 9.00.1406
Using Microsoft SQL Server 2005 JDBC Driver 1.2.2828.100
Ismo
and if it is possible, how?
I have tried "Read commited snapshot", nolock, readpast and all kind of combinations, but nothing seems to work properly.
both sessions runs same time with separed programs and both session have "autocommit off" mode
What I want to do:
SESSION 1:
create table a(a varchar(2));
insert into a values('1');
insert into a values('2');
commit;
select * from a;
A
-
1
2
2 row(s)
SESSION 2:
select * from a;
A
-
1
2
2 row(s)
SESSION 1:
update a set a='3' where a='1';
Processed: 1
SESSION 2:
update a set a='4' where a='2';
Processed: 1
SESSION 1:
select * from a;
A
-
3
2
2 row(s)
SESSION 2:
select * from a;
A
-
1
4
2 row(s)
# so both session saw only own updates and committed data.
# and both sessions can do those updates, they don't lock each other, because they don't handle same rows.
SESSION 2:
commit;
SESSION 1:
select * from a;
A
-
3
4
2 row(s)
SESSION 2:
select * from a;
A
-
1
4
2 row(s)
SESSION 1:
commit;
SESSION 2:
select * from a;
A
-
3
4
2 row(s)
# so only after COMMIT data chances.
but befoce commit both sessions can read committed data and own updates.
BUT if sessions try to update same row, then session must lock (or give exception)
the real problem aren't this simple, but this scenario shows whats is the problem. that scenario works all other databases, but I can't get it working in sqlserver.
I am using:
Microsoft SQL Server 9.00.1406
Using Microsoft SQL Server 2005 JDBC Driver 1.2.2828.100
Ismo