Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 OO Principles in SP Design

Author  Topic 

smokinmunky
Starting Member

3 Posts

Posted - 2008-07-11 : 12:17:49
Hello all,

When I create a database and create stored procedures for it I tend to create a lot of stored procedures to encapsulate their functionality.

For example I would probably create the following sp's for a table:
-User_Add
-User_Edit
-User_Get
-User_GetAll
-User_GetAllAdmin
-User_Delete


Recently, a coworker said that there were too many stored procedures in my project and that I should combine them. However, I disagree. Her recommendation was to combine the Add with the Edit stored procedures. And also to combine all of the gets into one stored procedure. Her argument, was that large number of stored procedures would make maintaining the db difficult in the future. My argument to her was that as much functionality should be encapsulated in the different stored procedures to be more OO like. Combining the functionality of an Add and an Update would only make the sp more complicated and introduce another point of failure. And the Gets in the above example all return different data. Having one Get that accepts a bunch of variables seems like it would over complicate things.

So what do you think? Are too many stored procedure a bad thing or should should I create as few stored procedures as possible and combine their functionality?


spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-07-11 : 12:34:28
think of your sprocs as a database interface to the outside world.
in oo an object should communicate with the outside world only through it's interface.
then there's the "keep it simple" principle.

too many sprocs aren't a problem with good naming conventions and schema use.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

LTack
Posting Yak Master

193 Posts

Posted - 2008-07-11 : 12:42:54
Thanks for this...it helps clear up some thoughts I've had on the issue as well. A fellow programmer and I have gone back and forth on our coding standards...we decided to agree to disagree...but I feel more justified now ;)

__________
SQL Newbie
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-07-11 : 12:49:23
well i have only one coding standard rule for sprocs:
always prefix your sprocs with "sp_"

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

smokinmunky
Starting Member

3 Posts

Posted - 2008-07-11 : 13:11:05
why is there a need prefix with sp_? In application development Hungarian Notation is on the way out, so why is there still a need for it in the database world?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-07-11 : 13:12:32
no, no, i was joking. whatever you do never use a "sp_" prefix for your stored rocedures.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-11 : 13:14:08
Don not use sp_, the database will look at the system stored procedures first and then the user defined ones, I use stp_

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

smokinmunky
Starting Member

3 Posts

Posted - 2008-07-11 : 13:17:09
I'm talking about stored procedure prefixing in general, is it really needed?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-07-11 : 13:21:11
no it's not needed. but it's nice to have because that way you can differentiate your objects quicker.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page
   

- Advertisement -