Sandeep
Sandeep

Reputation: 7334

Disable a list of users in Database

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?

Upvotes: 0

Views: 74

Answers (2)

Joel Etherton
Joel Etherton

Reputation: 37543

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.

Upvotes: 0

Chris Kooken
Chris Kooken

Reputation: 33938

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.

Upvotes: 1

Related Questions