7 Error handling, testing, source control, and deployment

 

This chapter covers

  • Handling T-SQL errors
  • Troubleshooting code
  • Performance testing
  • Modern development practices

When one thinks of the role of a database developer, it is easy to focus exclusively on writing efficient T-SQL code. In reality, however, the modern database developer has to consider many other things. Error handling is the first of these areas. If a procedure throws an error in production, we will want that error to be handled gracefully to mitigate risks such as inconsistent data. Error handling can even make a piece of code retry to avoid an application support team having to step in. We will invariably also want to be notified if an error does occur so that it can be investigated.

We also need to be able to debug code errors efficiently. Code ends up with bugs. That is a fact of life. When there are bugs in our code, we need to be able to debug them in an efficient manner. There is no point in writing a piece of code in a day if it then takes a week to debug it. Therefore, understanding debugging methodology is essential when working with complex code.

7.1 #26 Writing code that doesn’t handle errors

7.2 #27 Failing to alert on errors

7.3 #28 Not utilizing debugging functionality

7.4 #29 Not making use of Schema Compare

7.5 #30 Failing to write unit tests

7.6 Modern development techniques

7.6.1 #31 Not keeping code in source control

7.6.2 #32 Not deploying code with a CI/CD pipeline

Summary