Ozzie.eu

Love to code, although it bugs me.

Available Today: Windows Azure HDInsight with Hadoop 2.2

No comments
Link: Available Today: Windows Azure HDInsight with Hadoop 2.2

Big Data

No comments :

Post a Comment

This looks promising - new Google Sheets

No comments

No comments :

Post a Comment

Color, Value & Evolution of Logos: Infographic

No comments
How Big Businesses Like Ford or McDonald's Use The Power of Their Logos

No comments :

Post a Comment

This must be Christmas ...

No comments


First I got this: http://blogs.office.com/2014/03/17/onenote-now-on-mac-free-everywhere-and-service-powered/


Free OneNote for everyone :)


Then I read this:


http://googleblog.blogspot.pt/2014/03/save-more-with-google-drive.html


Two bucks a month? Sold!

No comments :

Post a Comment

Looks like the script I cooked up ...

No comments
Looks like the script I cooked up …:

… has everything to be a hit!


http://blog.ozzie.eu/post/79501121337/automatically-organizing-files-by-creation-date-into

No comments :

Post a Comment

Automatically organizing files by creation date into folders

No comments

I made this script for personal use, to organize photos after downloading them from the smartphone or memory card.


Maybe it’s useful to the rest of you:



No comments :

Post a Comment

Why dynamic TSQL should be banned from Stored Procedures

No comments


The guys from SQLServerCentral.com published an article giving a Quick Tour of sp_ExecuteSQL. This is all very well, except for the antibodies in me regarding dynamic TSQL inside frequently used stored procedures.

Yes, it’s true that “Every once in a while you find yourself working with SQL Server and you need to execute a piece of T-SQL that will be  different at the time of execution from the time that the code is being written.” but pointing out SQL injection as the single concern is quite an understatement.

The key downside events regarding dynamic TSQL are statement compile time and execution plans. You can read on the official documentation at MSDN: “The Transact-SQL statement or batch in the sp_executesql @stmt parameter is not compiled until the sp_executesql statement is executed. The contents of @stmt are then compiled and executed as an execution plan separate from the execution plan of the batch that called sp_executesql.”

Furthermore “sp_executesql can be used instead of stored procedures to execute a Transact-SQL statement many times when the change in parameter values to the statement is the only variation. Because the Transact-SQL statement itself remains constant and only the parameter values change, the SQL Server query optimizer is likely to reuse the execution plan it generates for the first execution.”

One can try to optimize this dynamic execution by using parameter substitution, so the the Transact-SQL string is built only one time. But there are still aspects you can’t control:


  • What is the generated execution plan for the dynamic statement, running separate from the execution plan of the batch that called sp_executesql;

  • Is the execution plan any good? You can’t really tell to try to change it;

  • Good or bad, the plan is cached for the following executions. If the diversity of queries that can dynamically be run is large, there’s no gain from the plan caching;

  • Using the RECOMPILE option solves the above issue but creates another: each time the stored procedure is called, the execution plan is recompiled. For long running queries this might be overlooked, but for queries otherwise fast, it’s a major performance drawback.

Having stated my displeasure for the dynamic TSQL, I can also recommend the following readings:


I apologize for the rant but in all applications I witnessed the development, using dynamic TSQL inside stored procedures caused nothing but trouble as soon as the tiny tables turned into a larger, business critical database with hundreds of users.

No comments :

Post a Comment