Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sql try catch method

Author  Topic 

desikankannan
Posting Yak Master

152 Posts

Posted - 2010-06-07 : 07:24:56
Hi,

iam was using sqlerver 2000 but now we are going to use sql 2005,
pls explain how to use try and catch with method with begin trans,commit trans, rollback trans.

Desikankannan

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-07 : 07:28:43
http://www.sqlteam.com/article/handling-sql-server-errors


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-06-07 : 08:13:46
[code]
create proc test
as
begin
begin try
begin transaction
declare @id int
insert into table1 (columns) select columns......

select @id = scope_identity()
insert into table2(columns)select @id,........

commit transaction
end try
begin catch
rollback transaction

select error_message()
return -1
end catch
end

[/code]
Go to Top of Page
   

- Advertisement -