Defensive Database Programming with SQL Server

Comments 0

Share to social media

(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.

Load comments

About the author

Jonathan Allen

See Profile

Jonathan Allen has been a SQL Server DBA since 1999, most enjoying performance tuning and development but also working with SSIS, SSRS to provide suitable business solutions. He is SQLSouthWest PASS Chapter Leader, blogs for Simple Talk, is a forum moderator at ask.sqlservercentral.com and is on Twitter. If you would like to find your nearest user group or just want to say hello then he would love to get an email from you.

Jonathan Allen's contributions