Defensive Database Programming Chapter 01

Today I am finally getting around to the review of the first chapter as promised.  I talked about the book a bit in the first post on the subject, which can be found here.  This book was written by Alex Kuznetsov (blog).

In this chapter, Alex discusses some basic defensive programming techniques.  That, in fact, is essentially the name of the chapter.  This is a pretty lengthy chapter – and with good reason.  Alex is laying the groundwork in this chapter with some basic samples and pretty much giving an introduction to the book.  The code samples are straight forward and designed to illustrate his point quite well.

During my current reading, a good takeaway from this chapter is the discussion on Rowcount.  For me, it serves as a prime reminder of the deprecation status as of SQL Server 2008.  If you are using SET ROWCOUNT, stop and change your practices.  Alex suggests using TOP in lieu of SET ROWCOUNT.

With each case that Alex presents as a potential problem when building your SQL code, he offers up a solution on how to avoid that problem.  The composition of using problems and providing solutions is quite handy.

And in Alex’s own words (Chapter 1 Summary, Page 59)

“It is vital that you understand and document the assumptions that underpin your implementation, test
them to ensure their validity, and eliminate them if they are not.”

No Comments - Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *

June 2010
« May   Jul »


  • @SQLSoldier: @mvelic Yes, but then I pointed out that they were using nolock and SSIS isn't. The matching records were not committed. #sqlhelp #TrueStory
  • @mvelic: It's just maddening because this lookup has *always* worked in the past. It's just now deciding to not recognize matches. #sqlhelp
  • @mvelic: Has anyone just seen an SSIS Lookup fail to make matches? You know the matches exist, but it doesn't connect them and it fails? #sqlhelp
  • @banerjeeamit: @MattPgh No. Current processing report is not visible. This is visible in RunningJobs table but not the stats breakdown. #sqlhelp
  • @forhakim: #sqlhelp in Visual Studio SSDT is there a way to make it NOT show table designer, only the script, when I edit a table?
  • @MattPgh: @banerjeeamit Will the current report show up in ExecutionLog? whatever processing is happening did not finish yet. #sqlhelp
  • @banerjeeamit: @MattPgh Look at the time processing and rendering in the logging table: #sqlhelp
  • @banerjeeamit: @MattPgh Also, CPU time can be consumed due to rpt processing. This is available thru the ExecutionLogStorage table #sqlhelp
  • @banerjeeamit: @MattPgh Using XEvents or profiler u can see which stmt r CPU intensive? This wud gv u the cpu time consumed by the DB queries. #sqlhelp
  • @MattPgh: Is there a way to tell exactly what SSRS service is doing when it has CPU pegged to 100%? like a "what running" query in sql. #sqlhelp

Welcome , today is Saturday, October 10, 2015