Pages

Ads 468x60px

Exception handling in sql server 2005 (use of try catch block in stored procedure).

USE [Organization]

GO

/****** Object: StoredProcedure [dbo].[Sp_InsertStudent] Script Date: 05/25/2011 12:15:37 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER proc [dbo].[Sp_InsertStudent](@name varchar(50),@marks int)

as

begin

insert into student(#name) values(@name)

end

begin

declare @id int

set @id= (select max(id) from Student)

begin try

insert into marks values(@id,@marks)

end try

begin catch

select 'Error Message:-' Error_Message() as Error_Msg

end catch

end

exec Sp_InsertStudent 'Ashish', 78

No comments:

Post a Comment