SQLServerCentral - www.sqlservercentral.com

A community of more than 1,600,000 database professionals and growing

Featured Contents

The Voice of the DBA

Your Thoughts On In-line SQL

Today we have a guest editorial as Steve is on vacation.

I want to start with my definition of in-line SQL. I define it as any SQL statement, such as: selects, inserts, updates, or deletes, where they exist in text form in an application.

I think there are really two opinions on this issue. There people that hate in-line SQL and then those that think it is great. I would guess that some of you, that are reading this article, are DBA’s and wish there was no in-line SQL in the applications or databases you support. Others of you are on more of the developer spectrum might like in-line SQL in your application. Personally, I think that in-line SQL should only be used in the rarest of situations where something just cannot be easily done without it. Basically, I prefer and advocate using stored procedures only for application access to the database.

Clearly, using stored procedures only in an application can help with security. Both in the rights you need to give users and to protect from SQL injection attacks. Still, there is another reason I think stored procs are better for application data access. I have found that when there are bugs or changes that are needed, there are many cases where just the stored proc can be changed and released instead of a new build of the application. I can’t tell you how many times we have been able to quickly test and release a stored proc change verses trying to get a new build of an application out.

So why do people use in-line SQL?  I know of a situation from a few years ago where the DBA was so slow to release changes to the database, the developers finally got tired of it and just moved everything to in-line SQL so they could better control releases and bug fixes. I am not sure if that is what the DBA wanted or not, but it was the result of the developers wanting more control to get releases / bug fixes out. I still don’t like in-line SQL, but I can see why someone could be driven to use it, just to try and get things done.

I think sometimes people use in-line SQL because it is less work at first. It is certainly more work to create the stored procedure, verses just drop a SQL statement into the application code. Still, I think it is less work only in the beginning. In the long run I believe stored procedures are less work and are easier to support over the life of an application.

Another good reason to use stored procedures only in an application is to be able to check dependencies. When all your database access exists only in stored procedures you can easily search those stored procs to find out how some change to the schema might affect existing SQL statements. When SQL statements are in-line they can be all over the place in code and not as easy to search accurately for them.

In the end you have to make the best decision you can for your situation and company. So how about you? What do you think about in-line SQL verses stored procs for database access in an application?

Ben Kubicek from SQLServerCentral.com

Join the debate, and respond to today's editorial on the forums

ADVERTISEMENT
SQL Provision

NEW SQL Provision: Create, protect, & manage SQL Server database copies for compliant DevOps

Create and manage database copies effortless and keeps compliance central to the process. With SQL Provisions virtual cloning technology, databases can be created in seconds using just MB of storage, enabling business to move faster. Sensitive data can be anonymized or replaced with realistic data to ensure data is protected as it moves between environments. Download your free trial

SQL Compare

The industry standard for comparing and deploying SQL Server database schemas

Trusted by 71% of Fortune 100 companies, SQL Compare is the fastest way to compare changes, and create and deploy error-free scripts in minutes. Plus you can easily find and fix errors caused by database differences. Download your free trial

Featured Contents

 

TEMPDB Enhancements in SQL Server 2016

Dharmendra Keshari from SQLServerCentral.com

TEMPDB Enhancements in SQL Server 2016 - By default enforced to follow best practices. More »


 

Data Encryption Using Always Encrypted in SQL Server

Additional Articles from Database Journal

The key challenge for application developers is to build a foolproof system to ensure data security. This is not only more intense, but more complex these days, as many organizations are planning to move their applications to the cloud. Read on to learn more. More »


 

Take the SQL Estate Data Mapping Survey and help shape Redgate’s products

Help Redgate to learn more about how SQL Server teams keep on top of sensitive data. If you're planning, or are already implementing, an information audit or data-mapping exercise for your SQL Server estate, please complete our short survey. More »


 

From the SQLServerCentral Blogs - 2.5 Ways Your ORM Is Vulnerable To SQL Injection

Bert Wagner from SQLServerCentral Blogs

Someone recently told me that they don’t need to worry about SQL injection because they are using an ORM. Oh boy. ORMs don’t... More »


 

From the SQLServerCentral Blogs - Identify the owner and then change the owner of a SQL Agent Job

David Postlethwaite from SQLServerCentral Blogs

In this post and video you will learn how to identify the owner and then change the owner of a... More »

Question of the Day

Today's Question (by Steve Jones):

What happens when I run this code in an AdventureWorks database?

 WITH mycte AS ( select id, price FROM (VALUES (999, 0.00) , (9999, -1.00) , ((SELECT p.ProductID FROM Production.Product AS p WHERE productid = 321) , (SELECT p.ListPrice FROM Production.Product AS p WHERE productid = 2) ) ) a(id, price) ) SELECT * FROM mycte 

Think you know the answer? Click here, and find out if you are right.


We keep track of your score to give you bragging rights against your peers.
This question is worth 1 point in this category: Table Value Constructor (TVC).

We'd love to give you credit for your own question and answer.
To submit a QOTD, simply log in to the Contribution Center.

ADVERTISEMENT

Design and configure SQL Server instances and databases in support of high-throughput applications that are mission-critical and provide consistent response times in the face of variations in user numbers and query volumes. Learn to configure SQL Server and design your databases to support a given instance and workload.

Pick up your copy of this great book today at Amazon today.

Yesterday's Question of the Day

Yesterday's Question (by Steve Jones):

Which components of SQL Server are shared by all instances on the same host, regardless of version?

Answer: SQL Browser and VSS Writer

Explanation:

Only the SQL Server Browser and the VSS Writer are shared across all versions on a host.

Ref: Work with Multiple Versions and Instances of SQL Server - click here


» Discuss this question and answer on the forums

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.

SQL Server 2017 : SQL Server 2017 - Administration

Upgrade SQL Server 2017 OS Question. - We are planning to upgrade our SQL server environment to 2017.  So which will the best OS 2012 vs 2016? What are...


SQL Server 2017 : SQL Server 2017 - Development

For Multiple DB - I want to execute this for Multiple DB how should I use this in Cursor DECLARE   @note VARCHAR(2000)   ,@id INT      DECLARE...

Replacing hidden characters - I'm to replace 2 hidden characters CHAR(0xC2) and CHAR(0x92). SELECT


SQL Server 2016 : SQL Server 2016 - Administration

Ginormous Production Log File - Help! - the log file for a database for a fairly small database is up to 46 Gig - and growing it is threatening...

Different unused table space on SQL Server 2012 vs 2016 - Hello, I have two servers (different versions) with two same databases, but on Server2 one table is more bigger than on...


SQL Server 2016 : SQL Server 2016 - Development and T-SQL

Using Bulk Insert or OPENROWSET to Import a CSV File - Morning Guys, I have a CSV file that is not playing fair. Which I have attached (the database has been sanitized...


SQL Server 2014 : Administration - SQL Server 2014

How to find if someone ran SQL profiler 2 days back - Hi Is there a way we can find if someone ran SQL profiler 2 days back?

What is faster? Creating calculated field within table or creating calculated fields within query? - Hi,  what is faster? Best, Jacek


SQL Server 2014 : Development - SQL Server 2014

Using a Case Statement to see if a Date is in the previous month or not - For a crazy calculation I need to do (it's part of a conditional across many fields)  I need to see...

null date parameter for a stored procedure - I have a stored procedure that has a parameter of date named dateStored. The default value is null. In the stored procedure...


SQL Server 2012 : SQL 2012 - General

How can i give Grant permission for synonyms from another database in same server. - Hi, I have two databases in same server.First data base some users already created.Second data base i created some synonyms related...

SSMS: First connection to DBMS takes over 15 minutes - So I have come across an odd issue on my workstation that I was hoping someone on here might be...

SSMS 2012 Database Connection Dialog Hangs - I have several users with an unusual problem with SSMS 2012. When they attempt to connect to a database using...


SQL Server 2008 : SQL Server 2008 - General

SQL Agent Job - Carry on Failure - Hi I have script that I run to fix orphaned user accounts on a instance - If I run the script in...

Extremely slow initial connection using ssms - For the last week or so anytime I load ssms to connect to my sql server, the initial connect takes...

SQL JOB Failing Unable to complete login process due to delay in prelogin response - Hi Experts, One of my SSIS job is failing due to error below. I have one server "A" where all SSIS...

Using the same partition function and scheme for multiple tables - I have a database where most of the tables have an integer field say "SetId" denoting a batch of data. If...


Cloud Computing : SQL Azure - Administration

getting 97% SOS_WORK_DISPATCHER and cannot find any information - hello, we are investigating performance issues on our application database and since turning on Azure Automatic Tuning am getting 97% waits...


SQLServerCentral.com : SQLServerCentral.com Website Issues

Links in forum posts - I seem to continuously have major problems when posting a response in the forum and including a link. I use...


SQL Server 2005 : Business Intelligence

Last Day of Month subscription for Shared SSRS schedule - I need to create a shared schedule in SSRS 2005 for the last day of the month. Not the last...

This email has been sent to newsletter@newslettercollector.com. To be removed from this list, please click here.
If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com.
This newsletter was sent to you because you signed up at SQLServerCentral.com.
Feel free to forward this to any colleagues that you think might be interested.
If you have received this email from a colleague, you can register to receive it here.
This transmission is ©2018 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
Contact: webmaster@sqlservercentral.com