Archive For The “SQL Server” Category

SqlDropDatabase, SqlCreateDatabase MSBuild tasks

When working with SQL, I often find I need to quickly spin up/tear down local developer database instances – for example, setting up a clean environment for integration tests on the build server, or blowing away test data. To help make this easier, here are a couple of MSBuild tasks I wrote that allow you [...]

Read more »

The road to automated database deployment

Working in an agile team means delivering software early and often — several times a day even. The only way to achieve this without going crazy doing releases all the time is to eliminate all the manual steps in your release process, until you’re leave with a single mouse-click to get your code into to [...]

Read more »

The trouble with soft delete

Soft delete is a commonly-used pattern amongst database-driven business applications. In my experience, however, it usually ends up causing more harm than good. Here’s a few reasons why it can fail in bigger applications, and some less-painful alternatives to consider. Tomato, Tomato I’ve seen a few different implementations of this pattern in action. First is [...]

Read more »

Powershell script to find orphan stored procedures

Working on a legacy application that uses over 2,200 stored procedures, it can be hard to keep track of which ones are still active and which can be deleted. Here’s a quick PowerShell script I wrote that locates stored procedures in a database that aren’t referenced by code or other database objects (assuming you have [...]

Read more »

Syntax for renaming a foreign key with sp_rename

Assuming the following tables: There is a typo in the foreign key name. How would you fix this using sp_rename? Is it… If you picked #2, you are correct. This took me 10 mins to figure out.

Read more »