Monday, October 1, 2012

Benefits of using stored procedure instead of writing codes in C#

Started from my favorite programming language, Visual Basic 6 (that was in 1997), I've been thinking where is the best place to implement the "business rule". After many years of moving the business rules from the the programming language to the database and vice versa, I've finally decided the best place for the business rule is in the stored procedure.

The simplest stored procedure is for SELECT, INSERT, UPDATE and DELETE. Indeed, you can do more than that. Benefits of using the stored procedure:
  • Create audit log when doing any of the CRUD operation.
  • Able to implement sophisticated control in what kind of data can be return to caller.
  • Easier to enhance/process the records before returning the records.
  • Stored procedure has been compiled and it runs faster than the ad-hoc query.
  • Able to enhance the stored procedure at anytime.
  • You don't have to recompile the application if there are any changes in the rule.
  • You don't have to redistribute the application (at client workstation or web server) if there are any changes in the rule.
Well, I know that you might not 100% agree with my argument. But, as a customize solution builder like me, we can't ask all the users to stop for a while and wait for the latest update.

No comments:

Post a Comment