Quantcast
Viewing all articles
Browse latest Browse all 10

Big Trys and Small Trans

Image may be NSFW.
Clik here to view.
triceps_0
Image may be NSFW.
Clik here to view.
tran

The catch phrase around the office these days is “Big Trys and small Trans.”  This came about as we were review stored procedure changes and I two suggestions.  First, that the entire procedure has a try…catch around it and second that the transaction be as small as possible.

Big Try

We’ve got standards in place that procedures have a try…catch in them.  One procedure had been copied, then modified with some logic to parse XML before the try.  I said lets move the try to above the XML parsing in case there’s an error in the XML, we’ll catch that as well.  So now we’ve got a bigger try.

Small Tran

The original code had the following steps:

  1. Start the transaction
  2. Look up some data
  3. Insert some data into a table
  4. Look up some other data
  5. Update another table
  6. Finally completed the transaction

In order to keep transactions small, I suggested the following:

  1. Look up all the data
  2. Start the transaction
  3. Insert the row into the table
  4. Update the row in the other table
  5. Finish the transaction

This will help avoid deadlocks and contention and keep things running smoothly.  There’s the smaller tran.

If you stick with the “Big Trys and Small Trans” methodology, it should help the following:

  1. Help avoid contention
  2. Help avoid deadlocks
  3. Catch errors earlier

Viewing all articles
Browse latest Browse all 10

Trending Articles