hi,
I am in process of evaluating that for simple CRUD operations(select,update,delete,insert), should we use stored procedures or should we fire queries directly from DAL for performance enhancement leaving aside the fact the stored procedure pproach will mix the data access and business logic .
If somebody could provide any microsoft URL link giving clearcut recommendation on the same,it would be of great help to me.
Regards

Stored procedure vs standard query
JLuis
I do have some remarks on the above, so I'll state them by the numbers used:
2. Yes, SQL Server stores all T-SQL exec plans in cache, but... be aware that SQL server matches the cache based on the exact text that makes up the statement. Therefor, if you use a value of some kind (and who doesn't), then you should always, ALWAYS use params in your sql to include them.
3. Again correct, only most of the time, if this is where you have to get your performance improvement, then I would think your problems are somewhere else. Most of the time, the return data is much more costly in bandwith then the actual statement send.
6. I agree strongly on this statement. I've been doing some bigger string manipulation in T-SQL and it becomes slow very easily. Try to avoid it! I mean it!
8. You should also consider Service Oriented Architecture. Basicly you could use webservice calls as easy as you can use SP's and still apply most of the advantages of SP's (including using the DB servers hardware) but then have it in managed code and making life a lot easier if you switch databases.
Vaish
TRID
Hi
Amazing discussin going on..
Can Roger (or somebody else) can comment on his statement that Stored procedures doing only CRUD operations are poor performing.
We need some technical details on the same as how it slow down the performance in this particular case
Cheers
tonofit
"14. Enhance security by minimizing some forms of attack"
Expanding on this
Dan_Dan
Another biggest advantage on SPs, you can increase the Security & control the SQL Injection...
You can control the DB Objects more secured, giving permission on SPs rathere than the Direct objects. So using those credential they are allowed to execute the SP rather than controlling the real time tables using (Insert/Update/Delete)..
wadnerk
Roger's answer was well said. I've worked on applications with a dynamic "chatty" dal that was very hard to optimize. The get method of many objects was tied to a sql statment to read on column. Often simple crud operations aren't performed on all tables and set based operations are what's needed.
In addition, the db can capture audit trails of what each user does and more importantly verify the state of the data and that the user has permission before allowing the operation. This is often done close to the data because most client apps now days are stateless.
A dynamic sql DAL's can be very hard to optimize if t-sql best practices aren't followed. It's so hard to accurately determine what sql is called most often and make sure its indexed properly. You can run sql traces to capture workfiles but you never feel confident you fully understand what's going on.
Using SP's in SQL 2005 applications will allow you to benefit from the runtime sql meta data that's new in sql 2005. This will make optimization so much easier.
The biggest reason to use SP's is to maintain an abstraction layer between the database schema and the object schema. If the layers have schema coupling it's incredibly difficult to optimize the database design independent of the object model and vice versa. Preserving that quality is invaluable when maintaining an application over time.
David Richards
Benjamini
Anything from Microsoft is going to almost always recommend using a stored procs. From what I have seen, there are only two disadvantages to using stored procs for CRUD:
1. You have to actually write them and maintain them
2. It ties your app to a specific RDBMS product (syntax is different in MS SQL, Oracle, Postgresql and no support in MySQL, etc.)
#2 is often not really an issue for most enterprise apps that are firmly settled into using a specific rdbms.
As for #1, keep in mind that there are many persistence frameworks out there that will automatically generate the CRUD sql statements for you, either from meta-data or pre-generated code.
Performance wise, there is very little (if any) difference in speed that I have personally ever noticed between a stored procedure and a parameterized query that is just doing simple inserts, updates or selects by primary key.
Hope that helps.
Saania
Actually for simple queries it doesn't make much difference whether you use sp or queries from app code.
only when it comes to complicated queries you have to make decision between performance vs maintainability/IPR/Security.
But CLR coming in SQL server may be that will also not be required.
http://DotNetWithMe.blogspot.com
vikas goyal
Gwenna
Pbr4Me
There is an article I really like that also talks about this. I hope this helps.
AlucardHellSing
Why Consider Stored Procedures
Mateusz Rajca
Hi,
Not sure if we do have any MS URL which can state this fact out of the box, but surely you can find performance tips on MSDN which will surely help you in this decision.
But I will take this opportunity to state my views here:
Regarding Mixing of Layer:
SP is always preferred way to do all operations in DB. Sorry so say, but my understanding is by using SPs, you are not mixing data layer with business logic layer. In my view SPs should be considered part of the BL Tier, and should be used in that way. Consider database as a two layered structure which has the core data storage and a layer on top of that which access the data as and when required. Now other app layers access this BL tier in DB directly or through other BL tiers. Once your SP start acting as BL tier, much of the DB related code moves inside them. So now we have all data related operations "nearer" to the data. Remember the old mantra from the gurus, all data intensive operations should be done as near to the data as possible. This holds true in this n-tiered architecture world also.
Regarding performance consideration:
As you have stated, SP will always have better performance output. SPs are compiled units and they are parsed, syntactically checked and execution plans already created. In case of arbitrary queries executed from DAL will be parsed and syntax checked every time the query is executed. If prepared statements are not used then a query execution plan creations also comes in play each time. So a new overhead.
In my opinion and in opinion of many industry Gurus whom I have read, maintain that SPs should be used as a part of BL and majority of DB operations should be done in them.
Hope this helps,
Regards,