So very recently our team had a lunch meeting presentation as we sometimes do where a person will give a presentation on a topic. This day Charlie gave a presentation on LINQ to entities. You can see the camtasia video here.
LINQ stands for Language Integrated Query. LINQ is very powerful and I like many things it offers. After meeting discussion turned to why developers write their own queries inside their applications (a.k.a. embedded sql). Developers and DBA's will clash over why you should/should not put sql in the application.
The developers point of view:
LINQ stands for Language Integrated Query. LINQ is very powerful and I like many things it offers. After meeting discussion turned to why developers write their own queries inside their applications (a.k.a. embedded sql). Developers and DBA's will clash over why you should/should not put sql in the application.
The developers point of view:
- I don't need a DBA or SQL Developer to complete my application. I just need a connection to the database and I'm golden.
- Writing stored procedures and waiting for the DBA slows me down.
- I have deadlines!
- Understanding the program is much easier if all the code is in one place and not spread to the sql server.
The DBA's point of view:
- SQL in the application requires the connection to have direct access to every table it will query. This could mean not only select priviledges but also insert, update, and delete priviledges. Imagine what a hacker could do with your connection! A better solution is to call a stored procedure. The stored procedure could have access to the tables, and the account connected would have access to only run the stored procedure!
- Developers do not write the best queries. Yep, believe it or not, a DBA or SQL developer will write better queries that are more efficient and return only the data needed. DBA's know how to use SQL trace, profiler, Database Tuning Advisor, query analyzer, etc, etc to ensure the query is optimized. More importantly, a DBA WILL use these tools whereas a developer might think "good enough". Argue this all you want but mechanics work best on cars, doctors work best on patients, DBA's work best on SQL Server. Always exceptions... but you are not one of them.
- DBAs responsible for the SQL server. Suppose a deadlock issue is found. Should the cause be a query that is inadvertently causing table locks and easily remedied no big deal right? Well now consider that it is 2am, the query is part of a web application that has embedded sql. Now the DBA cannot fix the query because it is not a stored procedure. Instead the production issue is escalated, the whole staff is fired, and all because you embedded sql! Ok that is over dramatic but it can lead to waking up programmers, shutting down the web application, or reoccurring problems until the application can be recompiled.
- Embedded sql requires the code to be compiled each time the application is run which will slow down the application. Not a big deal until you have a high transaction volume application.
Both points of view are valid! However, consider the long term health of the SQL Server. That server may need to support many applications. My point here is if you have DBAs and SQL developers that can optimize your queries, let them do it. Debate the results, revisit your queries, and let your DBA work for you. Your reward will be a better performing application and SQL Server.
Comments
Post a Comment