Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Why do we backup Active Directory ?

1099


Find columns used in stored procedure?

1038


How to rebuild master databse?

1127


How to create a trigger for insert only?

1084


how you can move data or databases between servers and databases in sql server? : Sql server administration

1030


What is for xml in sql server?

1137


While using a cursor, how can you differentiate between a deleted row and a row that has been inserted with null data values?

1106


How to connect Azure federated root database and apply federation in entity framework?

109


Can I use sql azure as a backup with log shipping or database mirroring?

156


What are alternate keys?

1029


How to update multiple rows with one update statement in ms sql server?

1262


What is sqlservr.exe - process - sql server (sqlex?press)?

1154


What is the most common type of join?

1038


Do you know nested transaction?

1001


How to write an inner join with the where clause in ms sql server?

1164