Monday, August 20, 2012

How many lines should be written in a stored procedure?

I have an experience while participating in a project. While reviewing the stored procedure done by the programmer, I was having problem in understanding the stored procedure not because of it is complexity but it's length. One stored procedure consists of a few thousand lines of code. I was scratching my head and asked myself is it necessary to write everything in one stored procedure? No. It should be break into many stored procedures and then call by the main stored procedure.

Our stored procedure development guideline is quite simple and straight forward where it must:

  • Must be able to re-test and/or re-use.
  • Must be written in a maintainable way - if the stored procedure is handling small process, then, it should be easier to maintain.
  • The stored procedure should contains less than 1,000 lines. I mean, that should be the maximum it should be.



No comments:

Post a Comment