Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have one Quotation. So many function are available(function,methods) in C# or any language. Why use/need Store Procedures/function of database?
Posted
Comments
SP HINGU 30-Jan-14 8:24am    
http://www.seguetech.com/blog/06/04/Advantage-drawbacks-stored-procedures-processing-data

There are a number of reasons:
1) It "focusses" procedures so they are easier to use in more than one application. For example, if a company uses a customer reference which is built from several fields, possibly in more than one table, then a Stored Procedure allows that to be done in one place, and called from several location - since they all use the same DB, they all use the same SP, and it makes it more reliable. Equally, it can return info as if it came from a single table whereas in reality it is retrieved from several via a complicated set of JOINs.
2) It can reduce bandwidth and / or processing use in transferring information from the DB to the application: if the processing is all done inside SQL then it can devise an execution plan that reflects the way it is being used. If you pull the same data back to the app, then you may well be retrieving information you don't need and wasting time that way.

There is a balance here: some things are good candidates for SP, others are best done locally. It's not a simple "use them for this" (or even "use them for everything" as some will probably tell you!).
 
Share this answer
 
I would like to add that Linq cannot update views. So for that you also would like to use sp. Yes, there are some tricks, but I prefer to use sp in this cases
 
Share this answer
 
v2
As an addition to Griffs comments:
3) They decouple your business logic from the database, you can make changes in the database and change the SP to reflect them, and the business logic would never need to know.
4) Safety, this is as far as I'm concerned the single most important reason. You can have a separate set of access rights to the stored procedures and have an extra user for your applications that only can use a set of stored procedures. So if for example your webpage gets hacked you have limited what kind of damage the hacker can do in the database.
 
Share this answer
 
Stored procedures are the way you interact with the database. PSQL does not understand the C# language so you need to write your INSERTS, UPDATES, DELETES, SELECTS, etc in Psql first. Then you use C# to interact your application with PSQl.
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900