Click here to monitor SSC

FatherJack

SQL Q+A forum at ask.sqlservercentral.com | Follow fatherjack on Twitter

Defensive Database Programming with SQL Server

Published Saturday, July 17, 2010 8:31 PM

(written by Alex Kuznetsov, published by Simple Talk Publishing 2010)

I wasn't entirely sure what to expect from this book, mostly because I don't think of myself primarily as a database programmer, I know how to write procedures and functions, how to manage a range of SQL Servers of various versions and editions and I can design a database for the modest needs of my employer but programming is done in VB right? Or C if you're a grown up! To that end I wasn't sure if it would have a lot of content that I could apply to my job. It got a glowing review from Joe Celko on his blog,  so I wanted to give it a read. Its available as a pdf for free from Simple Talk so there was nothing stopping me.

I needn't have worried, almost every page has something that is relevant to me. It's well organised and builds from one chapter to another with very clear examples of commonly used programming approaches, how they can become code time-bombs, ready to cause you headaches when something else in your system changes and how you can get in early, make some changes and prevent the issues occurring.

It's a little like having a security firm visit your house and tell you about the weaknesses that a criminal might exploit and best practices that you can adopt to make yourself less vulnerable. Planting a row of bushes across the front lawn right now seems like a good idea but in a few years they will give great cover to a burglar while he works on getting your spare room window open. Similarly, creating database objects right now may seem like good ideas, but if you don't consider what they might be used for in a few years time then it could cause all sorts of problems - such as does your code handle NULL adequately, are the CONSTRAINTS built to ensure your business rules are enforced in all circumstances, do your procedures have error handling that is appropriate? These are all points that Alex covers clearly and explains how and why they could be problems before providing a working example of how to avoid getting caught out. He also deals with TRIGGERS, Data Integrity and code re-use.

Alex covers some common T-SQL misconceptions such as the order of WHERE clause condition evaluation - its not guaranteed to be repeatable; to use ORDER BY if you want your data in a repeatable order; using SET and SELECT correctly; how SET ROWCOUNT and SET LANGUAGE can stop triggers working as intended.

This is a book that deserves a second read to re-enforce its concepts and reasoning and is certainly one that I am going to pass around the team in my office so that we can share its guidance and gain from its recommendations.

To sum up, another quality title from Simple-Talk Publishing that will be well used and kept at the closer end of my book shelf.

Area

Score
(1 Low/ 10 High)

Area Description
Readability

8

How easy the book is to read, how the sentences flow and the content is ordered. Not how technical the subject matter may be, for that level see Technical Range.
Relevance

8

How the book relates to my work and activities and therefore entirely subjective so may not apply to your needs.
Technical range

4-8

A low technical range would be suitable for DBA beginners, progressing up to 10 for DBAs that really ought to be writing their own books.

The book is available for free in pdf format here:
 http://www.simple-talk.com/books/sql-books/defensive-database-programming/ 
or to in printed format from
Amazon: http://www.amazon.co.uk/Defensive-Database-Programming-SQL-Server £19.99 and
Tesco: http://www.tesco.com/books/ £13.99 among others *.

 

* - Prices correct at time of upload and cannot be guaranteed.

by fatherjack
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

What do you think?

(required) 
(optional)
(required) 

About fatherjack

DBA since 1999 working for not-for-profit company. http://twitter.com/fatherjack,
<July 2010>
SuMoTuWeThFrSa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. David Wesley... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across, and start getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...