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
Why do we backup Active Directory ?
Find columns used in stored procedure?
How to rebuild master databse?
How to create a trigger for insert only?
how you can move data or databases between servers and databases in sql server? : Sql server administration
What is for xml in sql server?
While using a cursor, how can you differentiate between a deleted row and a row that has been inserted with null data values?
How to connect Azure federated root database and apply federation in entity framework?
Can I use sql azure as a backup with log shipping or database mirroring?
What are alternate keys?
How to update multiple rows with one update statement in ms sql server?
What is sqlservr.exe - process - sql server (sqlex?press)?
What is the most common type of join?
Do you know nested transaction?
How to write an inner join with the where clause in ms sql server?