HomeInterview QASuggestionBest Practices : Writing Stored Procedures

Comments

Best Practices : Writing Stored Procedures — 3 Comments

    • Hi,
      yes you are right, its not a general case.

      one of the reason we write stored proc is a functional modularity. but if you have lots of tables joined in SP and we are calling that SP many times then we should definately look for some good solution. so, when this is the case, we should need to review the number of joins we do in SP.

      here is the note i could find quickly from google: http://www.devx.com/dbzone/Article/33551/1954
      Section “Tips for Writing High-performance SQL” -> Point No. 7

      if you have more things add to this list pls share with us.
      Thanks, Khilit

  1. Hi there. All good and well… but you should almost always refrain from using hints in your production code, especially the dreaded NOLOCK. NOLOCK is VERY(!) dangerous and is equivalent to the READUNCOMMITED isolation level. And hints in and by themselves are a mechanism to bypass the (sophisticated and dynamic!) rules of the query optimizer. What happens when the rules change with the next release? With hints you not only get a maintenance nightmare but also risk very sub-optimal code. Also, the rule about seeks is not correct. Seeks are good for OLTP scenarios when your query is trying to target very few rows in a table. Scans is what you want in data warehousing. So, in a word – it all depends. Error handling and transaction management is best left to SET XACT_ABORT ON… There are many more reservations I’d have but don’t have time to expand upon them.

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>