How to handle errors in Stored Procedures.

Answer Posted / senthil

Error handling means if our stored procedure generates any error while running,we can handle that error.So that it will not show the error.

For eg.

insert into emp(sno,name,age) values(10,'Vasanth',26);

Consider field "sno" is primary key.When we are giving duplicate input to the sno it will show the error.

If you dont want to show the error ,you can capture the error and display as below.

BEGIN TRY
insert into emp(sno,name,age) values(10,'Vasanth',26);

END TRY

BEGIN CATCH
SELECT @err = @@error
IF @err <> 0
BEGIN
RETURN @err
END
END CATCH

Here in this case,it will capture the error and display.

Is This Answer Correct ?    12 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a join? : Sql server database administration

552


What is a table called, if it has neither cluster nor non-cluster index? What is it used for?

602


According to you what goes into making the best database administrator? : sql server database administration

551


Write a SQL queries on Self Join and Inner Join.

621


How to create a user name in a database?

592






What is the difference between sql server 2000 object owner and sql server 2005 schema? : sql server database administration

598


Characterize join and name diverse sorts of joins?

533


Is sql server difficult to learn?

528


how to overcome kernel isssues

1175


Explain system scalar functions?

583


What is surrogate key? : sql server analysis services, ssas

701


what are triggers? : Sql server database administration

508


How to add a new column to an existing table with "alter table ... Add" in ms sql server?

579


What is scrollable cursor?

545


What is the purpose of data source?

518