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
what is a join? : Sql server database administration
What is a table called, if it has neither cluster nor non-cluster index? What is it used for?
According to you what goes into making the best database administrator? : sql server database administration
Write a SQL queries on Self Join and Inner Join.
How to create a user name in a database?
What is the difference between sql server 2000 object owner and sql server 2005 schema? : sql server database administration
Characterize join and name diverse sorts of joins?
Is sql server difficult to learn?
how to overcome kernel isssues
Explain system scalar functions?
What is surrogate key? : sql server analysis services, ssas
what are triggers? : Sql server database administration
How to add a new column to an existing table with "alter table ... Add" in ms sql server?
What is scrollable cursor?
What is the purpose of data source?