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
explain different types of joins? : Sql server database administration
How do I create a trace in sql server?
What are data driven subscriptions?
what are different types of backups available in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration
Explain the steps to create and execute a user-defined function in the sql server?
What is a document index?
What is dirty read?
Explain the various types of concurrency problem?
Do you know what is similarity and difference between truncate and delete in sql?
What are the different types of data sources in ssrs?
what is an index? : Sql server database administration
What are the authentication modes in sql server? How can it be changed?
what is a join and explain different types of joins? : Sql server database administration
Explain transaction server implicit?
how can a database be repaired? : Sql server administration