Click here to Skip to main content
15,885,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My web project is using telerik dataaccess ORM,when I deal with the data,I can use stored procedures or direct write code.I find it is more efficient to use stored procedures.But some of my workmate say that using stored procedures is difficult to maintain, especially for some of the new recruits.Can anyone tell me when to use stored procedures and when direct write code in ORM better?
Posted

1 solution

Different programmers have different opinions about this topic.

I prefer to use stored procedures for two main reasons:

1. The structure of the database is hidden from the caller.
The caller only knows the format of the procedure.
This means that the database structure can change at any time as long as the SP returns the answer in the same way and doesn't change the input.
The client doesn't need to change at all.
This actually makes database administration easier.

2. It is easier to switch between different databases
Let's say you have two factories with one database each with the same functionality.
The two databases are maintained independently and can even be using different flavors, one use MySQL and one use Oracle.
By using stored procedures the client software can be kept the same and just some configuration is necessary.

The main drawback is that it can be quite a few stored procedures to create and they also need to be properly documented.
And as with interfaces in COM, you should never change the format of the procedure.
 
Share this answer
 
Comments
BillWoodruff 2-Nov-14 4:16am    
+5 excellent overview !
George Jonsson 2-Nov-14 4:34am    
Thanks Bill.
There are many arguments back and forth, but I wanted to keep it short.
PEIYANGXINQU 2-Nov-14 6:17am    
Thank.For your second reason,I think ORM has help me do this.Now my database has more than 40 sp.I wonder whether it has too stored procedures.
George Jonsson 2-Nov-14 6:31am    
Sure ORM hides the SQL query behind the scenes. However, if you have different table structures and naming convention for different databases you need to take care of this difference somewhere.
Using SP will make it easier to maintain even with ORM.

The number of SP depends on your requirement.
Maybe you can reduce some of them using parameters.
E.g. you have a method called SelectAllFromTable() and another called SelectSingleFromTable(int id)
you can probably replace both with SelectFromTable(int id) and define that id = -1 means Select all.

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