Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Another reason to use Stored Procedures

Another reason to use Stored Procedures

Scheduled Pinned Locked Moved The Lounge
databasecomcode-review
18 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J James R Twine

    Not to reopen the same can of worms :), but another reason I thought about last night was that if you use SPs instead of dynamic SQL, you have a way to further optimize things in the field without shipping a new app to the client.  I do not remember seeing that point mentioned in the _umpteen-hundreds_ of messages that thread contains! :)    That may be good reason or a bad one, but it is a reason...

    -=- James


    If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
    Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
    DeleteFXPFiles & CheckFavorites (Please rate this post!)

    R Offline
    R Offline
    Rocky Moore
    wrote on last edited by
    #4

    Yeah, this goes a long way at times. Often used to optimize or even to some table changes without having to modify code. While table changes usually end up in code changes (at least for added data), there are times when a simple change to a SP will do the job and the application can keep on going. If you keep all your queries in SPs, you can even split tables and only need to change the SPs as long as the parameters stay the same to the SP. I think on of the most important features though is for optimizing. When you find some routines that are running slow, it is handy to be able to change the methods of complex SPs combined with possible index changes or temp tables to help solve bottlenecks. Then there are the other times when you need to interface to a database of another application. If they use all SP, it can make your life much easier as you can see clearly how they handle their data. SPs are not the end all for every use type of thing, but they sure are handy in most situations. I guess that is why most leading DBs use them :) BTW, if you have not use the new CLR server side code, it is pretty handy too although much more closed since it is server side code in a DLL.

    Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: USA City Burnt To Death...

    1 Reply Last reply
    0
    • J James R Twine

      Not to reopen the same can of worms :), but another reason I thought about last night was that if you use SPs instead of dynamic SQL, you have a way to further optimize things in the field without shipping a new app to the client.  I do not remember seeing that point mentioned in the _umpteen-hundreds_ of messages that thread contains! :)    That may be good reason or a bad one, but it is a reason...

      -=- James


      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      DeleteFXPFiles & CheckFavorites (Please rate this post!)

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #5

      So, your point is encapsulation?

      J 1 Reply Last reply
      0
      • E ednrgc

        So, your point is encapsulation?

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #6

        No, there is a longer thread previously that I participated in regarding reasons to or not too use SPs.  This was another reason that I did not think of until later on.    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

        E 1 Reply Last reply
        0
        • J James R Twine

          No, there is a longer thread previously that I participated in regarding reasons to or not too use SPs.  This was another reason that I did not think of until later on.    Peace!

          -=- James
          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          See DeleteFXPFiles

          E Offline
          E Offline
          ednrgc
          wrote on last edited by
          #7

          I meant that your reason is really logic encapsulation. Separating the database logic (for that operation) to the stored procedure.

          J 1 Reply Last reply
          0
          • J James R Twine

            Not to reopen the same can of worms :), but another reason I thought about last night was that if you use SPs instead of dynamic SQL, you have a way to further optimize things in the field without shipping a new app to the client.  I do not remember seeing that point mentioned in the _umpteen-hundreds_ of messages that thread contains! :)    That may be good reason or a bad one, but it is a reason...

            -=- James


            If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            T Offline
            T Offline
            ToddHileHoffer
            wrote on last edited by
            #8

            I once wrote an application using 95% stored procedures. Well, I didn't use all stored procs so we granted a couple people dataWriter rights. The user decided to use Access to update tables and right his own SQL. From that point on dataWriter = denied and only stored procs were used.

            GameFly free trial

            1 Reply Last reply
            0
            • E ednrgc

              I meant that your reason is really logic encapsulation. Separating the database logic (for that operation) to the stored procedure.

              J Offline
              J Offline
              James R Twine
              wrote on last edited by
              #9

              Encapsulation is one reason to do it.  But my point was not specifically regarding encapsulation (encapsulation just for the sake of encapsulation is a bad thing to do, IMHO).  It was to provide an example where using SPs (not specifically encapsulation), provides a benefit over raw/dynamic SQL directly within an application.    Peace!

              -=- James
              Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              See DeleteFXPFiles

              E 1 Reply Last reply
              0
              • J James R Twine

                Encapsulation is one reason to do it.  But my point was not specifically regarding encapsulation (encapsulation just for the sake of encapsulation is a bad thing to do, IMHO).  It was to provide an example where using SPs (not specifically encapsulation), provides a benefit over raw/dynamic SQL directly within an application.    Peace!

                -=- James
                Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                See DeleteFXPFiles

                E Offline
                E Offline
                ednrgc
                wrote on last edited by
                #10

                I am not arguing the point that SPs are the better way to go. My point was that SPs usually encapsulate the data operations that are not specific to your app. An inline SQL statement would require a recompile and a distribution update. If your boss doesn't like SPs, another option would be a XML file that contains the SQL statements (obviously encrypted). But that is little help (if not a step backward) from actually placing it in the code.

                1 Reply Last reply
                0
                • J James R Twine

                  Not to reopen the same can of worms :), but another reason I thought about last night was that if you use SPs instead of dynamic SQL, you have a way to further optimize things in the field without shipping a new app to the client.  I do not remember seeing that point mentioned in the _umpteen-hundreds_ of messages that thread contains! :)    That may be good reason or a bad one, but it is a reason...

                  -=- James


                  If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  DeleteFXPFiles & CheckFavorites (Please rate this post!)

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #11

                  That's the biggest reason not to use stored procedures! How can you be sure the change will get into change control? And populated out to other clients as necessary? Nothing should get out a client without going through the proper review and testing procedure!

                  J 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    James R. Twine wrote:

                    another reason I thought about last night was that if you use SPs instead of dynamic SQL, you have a way to further optimize things in the field without shipping a new app to the client

                    Only if the SP interface doesn't change in anyway. 9 times out of 10, you're going to end up having to ship out code changes as well.

                    the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
                    Deja View - the feeling that you've seen this post before.

                    T Offline
                    T Offline
                    Todd Smith
                    wrote on last edited by
                    #12

                    If it requires changes 9 times out of 10 then perhaps things aren't being designed so well.

                    Todd Smith

                    J P 2 Replies Last reply
                    0
                    • J James R Twine

                      Not to reopen the same can of worms :), but another reason I thought about last night was that if you use SPs instead of dynamic SQL, you have a way to further optimize things in the field without shipping a new app to the client.  I do not remember seeing that point mentioned in the _umpteen-hundreds_ of messages that thread contains! :)    That may be good reason or a bad one, but it is a reason...

                      -=- James


                      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                      DeleteFXPFiles & CheckFavorites (Please rate this post!)

                      A Offline
                      A Offline
                      Andy Brummer
                      wrote on last edited by
                      #13

                      Another one is security within the database. In sql server as long as stored procedures don't use dynamic sql you can manage access rights to the procedures without giving clients access to the data tables directly. That way you can prevent them from writing custom queries on the data.

                      Using the GridView is like trying to explain to someone else how to move a third person's hands in order to tie your shoelaces for you. -Chris Maunder

                      1 Reply Last reply
                      0
                      • T Todd Smith

                        If it requires changes 9 times out of 10 then perhaps things aren't being designed so well.

                        Todd Smith

                        J Offline
                        J Offline
                        James R Twine
                        wrote on last edited by
                        #14

                        The design may be OK - the monkeys that did the implementation... well, that is another story! :)    Peace!

                        -=- James
                        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                        See DeleteFXPFiles

                        1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          That's the biggest reason not to use stored procedures! How can you be sure the change will get into change control? And populated out to other clients as necessary? Nothing should get out a client without going through the proper review and testing procedure!

                          J Offline
                          J Offline
                          James R Twine
                          wrote on last edited by
                          #15

                          PIEBALDconsult wrote:

                          How can you be sure the change will get into change control? And populated out to other clients as necessary?

                          A valid point. But just because the change is not part of the deliverable to all other clients does not mean that is is not being tracked.  Also, not all DB-based projects are limited to their own database.  Some have to act as add-ons to existing schemas.  Not all optimizations or changes, which may be specific to a particular client's environment, are suitable for all other clients.  I am not talking about the general bug fix scenario here.    The original discussion was about possible benefits of SPs.  This is a possible benefit, regardless of the dangers of its possible misuse.    Peace!

                          -=- James
                          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                          See DeleteFXPFiles

                          D 1 Reply Last reply
                          0
                          • J James R Twine

                            PIEBALDconsult wrote:

                            How can you be sure the change will get into change control? And populated out to other clients as necessary?

                            A valid point. But just because the change is not part of the deliverable to all other clients does not mean that is is not being tracked.  Also, not all DB-based projects are limited to their own database.  Some have to act as add-ons to existing schemas.  Not all optimizations or changes, which may be specific to a particular client's environment, are suitable for all other clients.  I am not talking about the general bug fix scenario here.    The original discussion was about possible benefits of SPs.  This is a possible benefit, regardless of the dangers of its possible misuse.    Peace!

                            -=- James
                            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                            See DeleteFXPFiles

                            D Offline
                            D Offline
                            Dan Neely
                            wrote on last edited by
                            #16

                            James R. Twine wrote:

                            Please rate this message - let me know if I helped or not!

                            Fishing for MVP status? How tacky. (2)

                            -- Rules of thumb should not be taken for the whole hand.

                            J 1 Reply Last reply
                            0
                            • T Todd Smith

                              If it requires changes 9 times out of 10 then perhaps things aren't being designed so well.

                              Todd Smith

                              P Offline
                              P Offline
                              Pete OHanlon
                              wrote on last edited by
                              #17

                              I'm possibly a bit biased here. Most of the time I'm called in to trouble shoot (fix) problems. For instance, in one company I had to redesign a system that was taking 186 hours (yes I did say hours) to process a weeks worth of accounts. In other words, it took into the following week to process last weeks accounts. By redesigning the SP and data layer, I got this down to less than an hour - and it wasn't that hard.

                              the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
                              Deja View - the feeling that you've seen this post before.

                              1 Reply Last reply
                              0
                              • D Dan Neely

                                James R. Twine wrote:

                                Please rate this message - let me know if I helped or not!

                                Fishing for MVP status? How tacky. (2)

                                -- Rules of thumb should not be taken for the whole hand.

                                J Offline
                                J Offline
                                James R Twine
                                wrote on last edited by
                                #18

                                Actually, I have had "Please rate this post" as part of my signature for quite some time now.  I just recently moved it and changed the wording a bit, though.    As far as fishing, if I do not deserve the vote, then do not provide one.    Peace!

                                -=- James
                                Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                                See DeleteFXPFiles

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups