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
Where is my database stored on the hard disk in ms sql server?
What is the sql server agent?
How do I start sql server 2017?
What is relationship? What number of sorts of relationship are there?
How many types of schemas are there?
What is NOT NULL Constraint in sql server 2012?
What is page in sql server?
which backup strategy you are following at ur company
You want to use bids to deploy a report to a different server than the one you chose in the report wizard. How can you change the server url?
How do I port a number to sql server?
Write a SQL command to insert and update only a particular field?
What are the restrictions that views have to follow? : SQL Server Architecture
How do I get Report Builder to generate a parameter that can be set by users viewing the report?
What is data block and how to define data block size?
What is the index requirement in SQL Azure?