Hi friends
I've written tow typeof code which do the same work, but I want to know which one is better? 1 or 2? Why?
I mean about Try & Catch.
Please Help me.
1.
ALTER Procedure [dbo].[Clerk_Insert]
@clk_Name nvarchar(80),
@clk_Family nvarchar(100),
@clk_FatherName nvarchar(80),
@clk_MeliCode char(10),
@clk_ShomarehShenasname char(10),
@clk_PersonnelNumber nvarchar(100)
As
Begin
Begin Try
Begin Tran a;
If exists(select clk_MeliCode, clk_Name, clk_Family, clk_FatherName, clk_PersonnelNumberfrom Clerk
where (clk_MeliCode = @clk_MeliCode)
or (clk_Name= @clk_Name and clk_Family= @clk_Family and clk_FatherName = @clk_FatherName )or( clk_PersonnelNumber=@clk_PersonnelNumber))
return -1;
End
else
begin
insert into Clerk
(clk_Name, clk_Family, clk_FatherName,clk_MeliCode, clk_ShomarehShenasname, clk_PersonnelNumber)
values
(@clk_Name, @clk_Family,@clk_FatherName,@clk_MeliCode,@clk_ShomarehShenasname, @clk_PersonnelNumber)
commit Tran a;
End Try
Begin Catch
Rollback Tran a;
select
ERROR_LINE() asline, ERROR_MESSAGE() as messages;
End Catch
2.
execute dbo.Clerk_Insert;
commit tran a;
ERROR_NUMBER() asError_Numbers,
ERROR_LINE() as Error_Lines,
ERROR_MESSAGE() asError_Messages;
rollback tran a;
End Catch;
go