Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Best Practices Expand / Collapse
Author
Message
Posted Thursday, March 20, 2008 11:40 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:29 PM
Points: 752, 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/
Post #472453
Posted Thursday, March 20, 2008 12:56 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:42 AM
Points: 14,037, Visits: 28,407
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
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #472501
Posted Friday, March 21, 2008 12:56 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, October 23, 2013 4:46 PM
Points: 310, 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
Post #473062
Posted Friday, March 21, 2008 12:59 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
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
Post #473064
Posted Friday, March 21, 2008 1:10 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 11:54 AM
Points: 9,294, Visits: 9,492
Procs are the industry best practice.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #473072
Posted Friday, March 21, 2008 1:43 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:29 PM
Points: 752, 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/
Post #473083
Posted Friday, March 21, 2008 2:07 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, October 23, 2013 4:46 PM
Points: 310, Visits: 244
Timothy,

The following articles may be of use to you.

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
Post #473095
Posted Friday, March 21, 2008 6:59 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 10:24 AM
Points: 1,865, Visits: 3,620
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.


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #473166
Posted Monday, March 24, 2008 9:25 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:29 PM
Points: 752, 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/
Post #473524
Posted Monday, March 24, 2008 10:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:49 PM
Points: 7,161, Visits: 15,651
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?
Post #473577
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse