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
Does a sql server 2005 select statement require a from?
What is a functions and types in sql server?
code to create procedure for taking databse backup in sql server or i have the query for it but what it's query returns means i want to show on my jsp that the databse backup has been taken on the basis of that return value.does it returns 0 or 1.wat is the code for that
What is the difference between executequery () and executeupdate ()?
What is sub query and its properties?
Can a rule be bound to any column of any data type?
How many servers can we create in a single subscription?
When we should use @@error?
What is the difference between clustered index and primary key?
Can you name a few encryption mechanisms in sql server?
What is the use of stored procedure?
How to execute a sql statement using odbc_exec()?
What is the difference between dbcc indexdefrag and dbcc reindex?
Who developed sql server?
Explain stored procedure?