Integrating SQL Server Tools Into SQL Change Automation Deployments

SQL Change

hen doing repetitive database work with SQL Change Automation (SCA) or SQL Compare, we often need to use other tools at the same time such as the registered servers in SQL Server Management Studio (SSMS), SQLCMD, and BCP. I also tend to use the SQL Server PowerShell module, sqlserver (formerly known as sqlps). This uses Server Management Objects (SMO), which is Nature's Way of interacting with SQL Server and uses the same .NET library that underlies SSMS.

You might also enjoy:  Simple Steps in SQL Change Automation Scripting

If you do so, you'll want to integrate all these tools as much as possible, and when you're scripting with PowerShell, use the same database connections as you are using with SCA. This article is all about how you do that. We'll show how you can start integrating SCA scripts with SSMS into a single process, and we'll also learn to stop fearing the connection string and view it as an ally. We will use one to create an SMO connection via a serverConnection object and borrow that same connection to execute BCP and execute a SQL Command.

The ‘= NULL’ Mistake and Other SQL NULL Heresies

The SQL Prompt Best Practice rule checks whether a comparison or expression includes a NULL literal ('NULL'), which in SQL Server, rather than result in an error, will simply always produce a NULL result. Phil Factor explains how to avoid this, and other SQL NULL-related calamities.

SQL Prompt has a code analysis rule (BP011) that checks whether a comparison or expression includes a NULL literal ('NULL'). These will always produce a NULL result. To determine whether a datatype is or isn’t NULL, use ISNULLor ISNOTNULL.

Continuous Learning

In case you can't tell from some of my blog posts, I'm a bit of an advocate for DevOps. I'm extremely fortunate in my employer, Redgate Software, that they are also huge advocates for DevOps. We not only teach it and promote it, and, oh yeah, make AWESOME tools for it, we practice DevOps in what we do.

However, this post is not about DevOps. Instead, I'm trying to leverage some of the concepts of DevOps, Continuous Integration and Continuous Deployment, to arrive at some ideas around learning that I want to share.