Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6024125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:06:34+00:00 2026-05-23T04:06:34+00:00

Are there any guidelines on when you should and should not write a long

  • 0

Are there any guidelines on when you should and should not write a long complicated 2000+ line stored procedure?

In my specific case this stored procedure contains a lot of if/then, case, goto and branching statements. It works by constructing SQL queries depending on inputs and results of queries and uses the execute statement to run the constructed queries. It can execute several constructed queries in one call and uses results of those queries to construct other queries to run.

It is pretty messy and hard to understand. Debugging is tough, the only way to know what is going on is to step through a call to see what it’s doing. There barely any exception handling or logging. Maintaining it is a pain. In fact, no one really knows what it does or how it was created and if we had to make modifications to it we would have to take a “cross your fingers and hope for the best” approach. But, I think it was done this way for performance reasons.

This procedure is used by many applications. The only other way I can think to do something like this is through a web service. It would probably be comparable in complexity, but a lot easier to understand. However, it would probably be multiple times slower as it would still have to make several calls to the database for 1 request.

So, my question(s) are, how do we decide when and when not to write long stored procedures?

Is there something I’m missing or do we just have to put up with our monstrous stored procedure?

Are there ways to structure and break down stored procedures into smaller components so they are easy to understand?

Will a stored procedure always be faster than anything else and the right choice when you need to make many calls to the database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:06:34+00:00Added an answer on May 23, 2026 at 4:06 am

    I’m not sure that it’s ever a good idea to write 2000+ LOC for a single function. My initial reaction is to say that your sproc should be broken up into smaller functions (table-valued or scalar, whatever is appropriate) and stored procedures (for non-query operations). However, that might just be moving the LOC around rather than simplifying the actual operation. Unfortunately, without any source code posted it’d be difficult to give more specific advice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any guidelines/best practices for deciding what type of data should be stored
Is there any guideline or rule for when the view state should be enabled
Are there any guidelines on writing database tests so that you can refactor database
Do you know any guidelines on how to create a new BlogEngine.net theme having
Is there any way to check whether a file is locked without using a
Is there any free or commercial component written in .NET (no COM interop) that
Is there any query which can return me the number of revisions made to
Is there any efficiency difference in an explicit vs implicit inner join? For example:
Is there any way to capture the MouseDown even from the .NET 2.0 TextBox
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.