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 the recovery model? List the types of recovery model available in sql server?
Explain what are the different index configurations a table can have?
What is the need for indexing?
Is sql server a database?
What is awe?
Why do we use functions?
Explain error and transaction handling in sql server?
What are the 2 types of classifications of constraints in the sql server?
Explain error handling in ssis?
What are diverse clauses that form a part of sql?
Would you store your query in a ssrs report or a database server? State the reason why?
What is apply operator in sql?
How to make a column nullable?
Introduction of rollup clause using sum and group by clause?
What is cube dimension? : sql server analysis services, ssas