Is using Commit in a transaction enough or I should use rollback too.
tabel1
name nvarchar(10)
family nvarchar(20)
table 2
name nvarchar(10)
family nvarchar(20) not null
begin transaction
insert into table2 (name) values('john')
insert into table1 (name,family) values('Joe','Lando')
commit transaction
as you see the first statement has error. should I use rollback somewhere?
You can skip ROLLBACK if you use SET XACT_ABORT ON (SQL Server 2000 link)
From the link:
Now, if you don’t use it you need rollback. Or close your connection.
One useful side effect of SET XACT_ABORT ON is that after a client CommandTimeout event, locks are released and the transactions rolled back. Otherwise, it doesn’t happen until the connection is hard removed from SQL Server: it can stay open because of pooling.
Your bible should be “Error Handling in SQL 2000 – a Background” by Erland Sommarskog: read it. And on SO: Do I really need to use "SET XACT_ABORT ON"?