views:

31

answers:

2

Hi All,

I have a simple question regarding best practices in programming.

I have a DB which contain members. After some processing I get a list of users who need to be disabled in DB.

I have a stored procedure which takes UserId as Input and disable the user.

Since I am sure that I always have to disable more than one user, I am thinking to make input parameter for stored procedure as a Array of Ids rather than Id.

By doing this I thought I don't have to invoke the SP n times.

Is this a good programming practice?

+3  A: 

That question is a little subjective, however less trips to the database is always better. If you can minimize that, I would say go for it.

I have written several complex SProcs in the past that function in the same way. In the end one of the main reasons we write SProcs is for performance tuning. If this is one of the ways to do it, then so be it.

Climber104
I wouldn't say always. It depends on what is on the other end of the tradeoff.
JohnFx
good point, I should say more times than not...
Climber104
A: 

Yes. This will reduce the number of trips the code needs to make to the database which will result in less overhead to the application in question. I'm personally not a big fan of stored procs, but this is an ideal usage for them.

Joel Etherton