Computer ScienceScience & MathematicsEconomics & FinanceBusiness & ManagementPolitics & GovernmentHistoryPhilosophy

Defensive Database Programming with SQL Server

by Alex Kuznetsov

Defensive Database Programming with SQL Server

Subscribe to new books via dBooks.org telegram channel

Join
DescriptionTable of ContentsDetailsHashtagsReport an issue

Book Description

Resilient T-SQL code is code that is designed to last, and to be safely reused by others. The goal of defensive database programming, the goal of this book, is to help you to produce resilient T-SQL code that robustly and gracefully handles cases of unintended use, and is resilient to common changes to the database environment.

Too often as developers, we stop work as soon as our code passes a few basic tests to confirm that it produces the 'right result' in a given use case. We do not stop to consider what other possible ways in which the code might be used in the future, or how our code will respond to common changes to the database environment, such as a change in the database language setting, or a change to the nullability of a table column, and so on.

In the short-term, this approach is attractive; we get things done faster. However, if our code is designed to be used for more than just a few months, then it is very likely that such changes can and will occur, and the inevitable result is broken code or, even worse, code that silently starts to behave differently, or produce different results. When this happens, the integrity of our data is threatened, as is the validity of the reports on which critical business decisions are often based. At this point, months or years later, and long after the original developer has left, begins the painstaking process of troubleshooting and fixing the problem.

Would it not be easier to prevent all this troubleshooting from happening? Would it not be better to spend a little more time and effort during original development, to save considerably more time on troubleshooting, bug fixing, retesting, and redeploying?

This is what defensive programming is all about: we learn what can go wrong with our code, and we proactively apply this knowledge during development. This book is filled with practical, realistic examples of the sorts of problems that beset database programs, including:
- Changes in database objects, such as tables, constraints, columns, and stored procedures
- Changes to concurrency and isolation levels
- Upgrades to new versions of SQL Server
- Changes in requirements
- Code reuse
- Problems causing loss of data integrity
- Problems with error handling in T-SQL

In each case, it demonstrates approaches that will help you understand and enforce (or eliminate) the assumptions on which your solution is based, and to improve its robustness. Ultimately, the book teaches you how to think and develop defensively, and how to proactively identify and eliminate potential vulnerabilities in T-SQL code.

This open book is licensed strictly for personal or educational use. You can download Defensive Database Programming with SQL Server ebook for free in PDF format (8.6 MB).

Table of Contents

Chapter 1
Basic Defensive Database Programming Techniques
Chapter 2
Code Vulnerabilities Due to SQL Server Misconceptions
Chapter 3
Surviving Changes to Database Objects
Chapter 4
When Upgrading Breaks Code
Chapter 5
Reusing T-SQL Code
Chapter 6
Common Problems with Data Integrity
Chapter 7
Advanced Use of Constraints
Chapter 8
Defensive Error Handling
Chapter 9
Concurrent Queries and Transaction Isolation Levels
Chapter 10
Developing Modifications that Survive Concurrency

Book Details

Title
Defensive Database Programming with SQL Server
Subject
Computer Science
Publisher
Red Gate
Published
2010
Pages
389
Edition
1
Language
English
ISBN13 Digital
9781906434458
ISBN10 Digital
190643445X
PDF Size
8.6 MB
License
For personal or educational use

Related Books

SQL Server Internals: In-Memory OLTP
The SQL Server 2016 In-Memory OLTP engine (a.k.a. Hekaton) is designed to exploit terabytes of available memory and high numbers of processing cores. It allows us to work with memory-optimized tables and indexes, and natively compiled stored procedures, in addition to the disk-based tables and indexes, and T-SQL stored procedures, that SQL Server h...
Migrating SQL Server Databases to Azure
SQL Server is Microsoft's relational database management system (RDBMS). SQL Server can now be hosted entirely in Microsoft Azure, either in a hosted virtual machine (VM) or as a hosted service. Hosting a virtual machine in Azure is known as infrastructure as a service (IaaS), and hosting a service in Azure is known as platform as a service (P...
Learning Microsoft SQL Server
Microsoft SQL Server is a relational database management system developed by Microsoft. It is an unofficial and free Microsoft SQL Server ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow....
Data Science with Microsoft SQL Server 2016
R is one of the most popular, powerful data analytics languages and environments in use by data scientists. Actionable business data is often stored in Relational Database Management Systems (RDBMS), and one of the most widely used RDBMS is Microsoft SQL Server. Much more than a database server, it's a rich ecostructure with advanced analytic ...
SQL Server Execution Plans, 3rd Edition
Every Database Administrator, developer, report writer, and anyone else who writes T-SQL to access SQL Server data, must understand how to read and interpret execution plans. My book leads you right from the basics of capturing plans, through how to interrupt them in their various forms, graphical or XML, and then how to use the information you fin...
Protecting SQL Server Data
In Protecting SQL Server Data, John Magnabosco demonstrates how sensitive data, stored in SQL Server, can be protected using an efficient and maintainable encryption-based data architecture. He explains how to assess and categorize data elements according to sensitivity, regulate access to the various categories of data using database roles, vie...