I agree totally.  And one completely-missed value of stored procedures is that they 
provide a
layer of isolation from the raw database structure, allowing one to change the 
structure without
breaking code.  This applies to views, functions, etc. as well.  Making a distributed 
partitioned
view is still the best way to support huge data volumes in SQL Server (according to 
Microsoft--
I've never had to do it, thank God, since I've read about all the problems with it).

Compilation of complex queries alone can lead to huge overhead that can easily be 
avoided with
stored procedures, by the way.  Frans stated it correctly when he said that stored 
procedures
can't be used well with things that dynamic queries do well: changing types of return 
values, etc.
 That doesn't mean anything, though, but that you shouldn't use stored procedures in 
those
particular situations!  The very great bulk of queries aren't like that; they're 
pedestrian,
setting and getting a few values, etc.

You (the general you, not james specifically) can say what you want, but there's no 
situation in
which stored procedures are a good fit (non-dynamic SQL) that they shouldn't be used 
from a
performance perspective.  I have many times had to tune an application using dynamic 
queries, and
it is always the case that taking those queries, if possible, and putting them in 
stored
procedures has an immediate and beneficial effect on performance.  No matter how smart 
a database
server is, no matter how well it caches full or partial query plans, parsing and 
compiling
overhead is never negligible for a very busy transactional server.  Network latency is 
usually
secondary to this in importance, but not always.  I view it this way: a database 
server has a huge
workload already with maintaining and updating all those indexes, compiling 
statistics, providing
access control, transaction support, etc.  Why burden the poor thing more than you 
absolutely have
to?

I'm now a certified SQL Server DBA, but I most often write code all day at work.  In my
experience, people who advocate too strongly against stored procedures hate the idea 
that some
fuddy duddy of a DBA should have control over even persistence logic in an 
application, or that
they may be unable to get access to change something if they need to.  DBAs who don't 
know how to
code are always trying to stuff too much logic into stored procedures.  I believe that 
the wise
developer realizes that a (good) DBA can exploit the features of a particular DB 
server much
better than your average fool of an ASP developer, and a wise DBA realizes the 
advantage of
letting the (competent) application developer do his/her thing too!

Oh, and by the way, I think that network knowledge and security knowledge go together, 
and so do
database knowledge and programming knowledge; I'm talking about in the general 
programming world,
especially the business world.  I'd never call somebody an ace programmer (in the 
business world)
if they didn't know jack about databases, and I'd never call someone an ace DBA who 
scoffed at
programming in C#, for instance, and said everything should be coded as stored 
procedures (I work
with someone like this).  An even more experienced programmer makes the leap to the 
other camp and
starts learning everything possible about networking and security that his overloaded 
memory can
handle.  The person who winds up with all of this actual knowledge, instead of things 
read in
blogs, usually knows when it's a good idea to use a stored procedure, and when not to.

Jeff


--- james <[EMAIL PROTECTED]> wrote:
> >         However there are positive sides to the stored procedure
> aspect
> > though but they have nothing to do with performance or security. They
> > have everything to do with how you look at things. If you think an
> RDBMS
> > should provide the first 'tier' in a system, which automatically
> implies
> > it should offer some kind of API, stored procedures are the way to go.
> > It's defining the RDBMS' stored proc API as a service. You can also
> > provide that service by a tier outside teh RDBMS though, for example
> > with a DAL, written using an O/R mapper.
>
> >As for your statement above, there is another point of view different
> than >the
> >database as "first tier", database as an external api, and a
> transparent >view
> >of a database offered by OR tools.  I blogged about it..
>
> I see lots of discussion and Boggs ;-D about Stored Procedures vs.
> Static Queries.
>
> These however are only two of many ways to properly exploit any good SQL
> Server.
>
> What about Functions, User Functions, User Types, or even Indexed Views
> (a.k.a. materialized views in Oracle).
>
> I know I could not write an application without a Function in it, so why
> should my DB be any different?
>
> I know this is not usually the "Business" or Realm of application
> developers to make such radical changes in the Database Schema.
>
> I have discovered though that these RDBMS features are some of the
> things that make my work with MS SQL 2000 seem more fulfilling than
> runtime queries to an Access Database via an ODBC DSN.
>
> That is my $0.002 on the whole thing.
>
> ===================================
> This list is hosted by DevelopMentor�  http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to