Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Best Practices


Best Practices

Author
Message
timothyawiseman
timothyawiseman
SSC Eights!
SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)

Group: General Forum Members
Points: 802 Visits: 920
We are looking at rewriting a lot of our older code currently and looking at implementing new standards, but one point of question between different areas is where is the best place to execute queries? Is it generally better to have sql queries stored within the .Net code itself or to force the developers to do all interfacing with the database through stored procedures?

My current belief is that it is better to do it through stored procedures. This will help with security and allow small tweaks to be made on the back end without forcing recompiles and complete redeployment of the front end application for each one. It also more clearly compartmentalizes the code.

But is there something I am overlooking? Is this truly the best practice? And if so, is there more information to help bolster my case?

---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17599 Visits: 32267
Is this a plant? Are you looking to start a fight?

Well, I'll answer anyway.

My .00001 cents on this issue is, yes, use stored procedures as a standard method of development. First off, you get more granular security through the stored proc than you can through VB code. Second, you get more modular code by putting the code for database access into the database itself, allowing you to make changes to the internals of a query without having to redeploy the app.

You'll hear that performance will change in one direction or the other. That's not entirely true. If a reusable execution plan is generated from code or from TSQL, it doesn't really matter.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Dcarlson
Dcarlson
Old Hand
Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)

Group: General Forum Members
Points: 312 Visits: 244
I have to agree with Grant. There are possible exceptions, but as a rule sprocs are the best standard for db access.

----------------------------------------------------------------------------
"No question is so difficult to answer as that to which the answer is obvious." - George Bernard Shaw
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
Procs. Definitely.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9438 Visits: 9517
Procs are the industry best practice.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
timothyawiseman
timothyawiseman
SSC Eights!
SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)

Group: General Forum Members
Points: 802 Visits: 920
Thanks for your help. And I was looking for help in an argument I am in, Grant. If I was right (and the consensus here seems to be that I am) I wanted more arguments to bring to bear in convincing my coworkers. If I was wrong I wanted to be able to change positions before I got myself too entrenched.

Any other arguments that might help sway my coworkers?

---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Dcarlson
Dcarlson
Old Hand
Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)Old Hand (312 reputation)

Group: General Forum Members
Points: 312 Visits: 244
Timothy,

The following articles may be of use to you.w00t

http://www.sqlservercentral.com/articles/Security/updatedsqlinjection/2065/
http://www.mssqltips.com/tip.asp?tip=1455
http://www.sommarskog.se/dynamic_sql.html
http://msdn2.microsoft.com/en-us/magazine/cc163917.aspx

----------------------------------------------------------------------------
"No question is so difficult to answer as that to which the answer is obvious." - George Bernard Shaw
Marios Philippopoulos
Marios Philippopoulos
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1954 Visits: 3740
timothyawiseman (3/21/2008)
Thanks for your help. And I was looking for help in an argument I am in, Grant. If I was right (and the consensus here seems to be that I am) I wanted more arguments to bring to bear in convincing my coworkers. If I was wrong I wanted to be able to change positions before I got myself too entrenched.

Any other arguments that might help sway my coworkers?


Sprocs offer tight data security (and encapsulation) that can be easily and efficiently managed by a DBA team. (By encapsulation I mean that the client does not need to know which tables/columns were accessed for the returned data - neither should it know).

Also, sprocs serve to better organize database-access code, meaning better code maintenability and reusability.

You will not get these advantages from db code embedded directly in your client app.

__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables
Persisting SQL Server Index-Usage Statistics with MERGE
Turbocharge Your Database Maintenance With Service Broker: Part 2
timothyawiseman
timothyawiseman
SSC Eights!
SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)

Group: General Forum Members
Points: 802 Visits: 920
Thank you, DCarlson and Marios. The list of links and points were very useful.

---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Matt Miller (#4)
Matt Miller (#4)
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7641 Visits: 18084
There's also the data layer vs data ACCESS layer vs Business Layer argument. Embedding SQL calls just screws up the separation in my mind. It's not always a valid argument IMO, but it's kind of a big hammer when you discuss best practices.

Also - assuming you actually have a DBA role - you're undercutting the "specialist" and any optimization they might be able to provide by not putting the code in a place they can access. I mean - your devs don't REALLY want the DBA monkeying with their code? Well - in order to do their part of the job, the DBA's would kind of HAVE to if the SQL code isn't up to snuff. And the code would have to be recompiled and redeployed, just to fix SQL performance. That in itself is a costly scenario.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search