Where am I making mistake?
I want to automatically rollback the inserts as I am
trying insert duplicate rows.
begin tran TRAN1
begin
delete from test
insert into test(x,y) values (2,12)
insert into test(x,y) values (3,12)
insert into test(x,y) values (3,12)
select * from test
end
commit tran TRAN1
else
rollback tran TRAN1
Result :
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Msg 2627, Level 14, State 1
Violation of PRIMARY KEY constraint 'PK___1__10': Attempt to insert
duplicate key in object 'test'.
Command has been aborted.
x y
----------- -----------
2 12
3 12
(2 row(s) affected)
-----------
0
(1 row(s) affected)
Sathyan