Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Asheej T K
(187)
Alwyn
(165)
Avinash Mohan
(88)
Last 7 Days
Alwyn
(1087)
Asheej T K
(760)
Avinash Mohan
(551)
more...
Resources
»
Articles
»
Databases
»
Try Catch functionality in SQL Server 2005
Posted Date: 16 Jun 2009
Resource Type:
Articles
Category:
Databases
Author:
Rohit
Member Level:
Gold
Rating:
Points
: 4
I came across an interesting and useful feature of SQL server 2005, which helps in writing clear and easy SQL code.
Earlier if we have to do some transaction handling in a procedure based on the error returned in any SQL statement we used to check for error after every statement and rollback if necessary, with introduction of TRY and CATCH functionality in SQL server 2005 it has become very clear and methodical.
Earlier it was like:
Begin Transaction
SQL statement 1
If @@Error <> 0
Rollback
SQL statement 2
If @@Error <> 0
Rollback
SQL statement 3
If @@Error <> 0
Rollback
SQL statement 4
If @@Error <> 0
Rollback
Commit Transaction
Now we can do it like:
Begin TRY
Begin Transaction
SQL statement 1
SQL statement 2
SQL statement 3
SQL statement 4
Commit Transaction
End Try
Begin Catch
Rollback
End Catch
So if any error comes then the code would not execute commit and jump to catch block where we can do error handling and rollback.
Please see following link for some example.
For more details, visit
http://msdn.microsoft.com/en-us/library/ms179296(SQL.90).aspx
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
Try catch in Sql server 2005
.
Try
.
Catch
.
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
SQL Information
Previous Resource:
Tips - Optimization of SQL queries
Return to Discussion Resource Index
Post New Resource
Category:
Databases
Post resources and
earn money
!
More Resources
SQL Information
Automatic GridView Header
Database Design Tips & Tricks – Part 1
Triggers
Optimizing sql server queries
Sql Server Tips, Tricks and suggestions
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use