Wednesday, March 28, 2012

insert/update procs

Is it a good idea to consolidate both insert/update for a given table in one
stored proc?
I was thinking its always better to separate the two.
TIA.Trisha wrote:
> Is it a good idea to consolidate both insert/update for a given table
> in one stored proc?
> I was thinking its always better to separate the two.
> TIA.
I've seen it done both ways. With a combined proc, you need a way to
distinguish between an update and an insert. That's easy if you're
passing in a PK identity value (or NULL in the case of an insert). it's
easy to return the newly generated value using SCOPE_IDENTITY(). You
need to test the performance to see if a combined proc holds up without
recompiling. If you're using natural keys, then you'll need to test for
row existence or update and check @.@.rowcount. This is when I might turn
to separate procs.
David Gugick
Imceda Software
www.imceda.com

No comments:

Post a Comment