Stored Procedure with Try Catch in SQL

-- =============================================         
-- Author:  <SARAVANANS>         
-- Create date: <22-NOV-14>         
-- Description: <Common sp to update employee details>         
-- [usp_update_employee] 1       
-- =============================================         
CREATE PROCEDURE [dbo].[usp_update_employee]           
 @EmployeeID INT ,
 @EmployeeSalary MONEY
AS         
BEGIN TRY         
       
SET ARITHABORT  ON       
SET NOCOUNT ON   

UPDATE EMPLOYEE SET EMPLOYEESALARY =@EmployeeSalary WHERE EmployeeID =@EmployeeID 

END TRY         
BEGIN CATCH         

  SELECT @ErrorNumber=Error_Number(),
@ErrorState=Error_State(),
@ErrorSeverity=Error_Severity(),
@ErrorLine = Error_Line(),
@ErrorProc=Error_Procedure(),
@ErrorMessage= Error_Message(),
@userName=SUser_SName(),
@ErrorDate=Getdate() 

RAISERROR (@ErrorMessage, -- Message text. @ErrorSeverity, -- Severity. @ErrorState -- State. );  

END CATCH 

Comments

Popular posts from this blog

Types of Architects

Basic measurements

Search html table contents based on its td using Jquery