In Joe Celko’s Stairway to Database Design series, he writes:
The rules of thumb for T-SQL are not to write any procedure over 50 lines (one page)
This seems so radical at first, but it has precedence in NASA’s 10 Rules for Developing Safety-Critical Code:
Avoid complex flow constructs, such as goto and recursion. All loops must have fixed bounds. This prevents runaway code. Avoid heap memory allocation. Restrict functions to a single printed page. Use a minimum of two runtime assertions per function. Restrict the scope of data to the smallest possible. Check the return value of all non-void functions, or cast to void to