When should I use stored procedures?

前端 未结 19 2499
眼角桃花
眼角桃花 2020-12-04 10:53

When should I be using stored procedures instead of just writing the logic directly in my application? I\'d like to reap the benefits of stored procedures, but I\'d also lik

19条回答
  •  失恋的感觉
    2020-12-04 11:40

    I tend to avoid stored procedures. The debugging tools tend to be more primitive. Error reporting can be harder (vs your server's log file) and, to me at least, it just seems to add another language for no real gain.

    There are cases where it can be useful, particularly when processing large amounts of data on the server and of course for database triggers that you can't do in code.

    Other than that though, I tend to do everything in code and treat the database as a big dump of data rather than something I run code on.

    Consider Who Needs Stored Procedures, Anyways?:

    For modern databases and real world usage scenarios, I believe a Stored Procedure architecture has serious downsides and little practical benefit. Stored Procedures should be considered database assembly language: for use in only the most performance critical situations.

    and Why I do not use Stored Procedures:

    The absolute worst thing you can do, and it's horrifyingly common in the Microsoft development world, is to split related functionality between sproc's and middle tier code. Grrrrrrrr. You just make the code brittle and you increase the intellectual overhead of understanding a system.

提交回复
热议问题