SQL Server Development Tips – Automated, Incremental Builds

SQL Server DevelopmentThe black-box mechanics of SQL Server can make database versioning a challenge.  Traditional approaches include keeping a log of all structural SQL changes, or taking backup snapshots at development milestones.   The primary weaknesses of these approaches are the lack of flexibility and prototyping with the first, and deployment challenges with the latter.  Herein we present a solution to the challenge using version control and automated, incremental build scripts.

Many database developers, especially those from an in-house software background, view the database as an ecosystem – a living menagerie of the company’s information.  Although this approach is effective for large database instances with one deployment target and several staging/test environments, software developed for production release to multiple customers can take a different, more effective approach by treating the database similar to the software codebase.  This consists of three primary changes to database development methods – versioning the SQL structure, creating standardized sample data, and developing a set of scripts for one-line testing and deployment.

Versioning the database SQL structure is relatively straightforward.  Although testing and prototyping SQL statements against a live database through SQL Manager is encouraged, any final SQL that will be shared with the software should be coded in a set of create and alter statements.  These files should also populate standard system-level parameters and data, and contain any necessary grants and permissions.  Once any database update is finalized, the entire database should be dropped and recreated using the build scripts, before deployment to the test environment.

Although SQL statements could be organized by table, it is often more effective to group the SQL by function.  For instance, auditing code could be handled in one SQL file, lists of values in another, the menu system in a third, and so on.  This method of organization helps facilitate code reuse, and reduces development time of future projects.

Next, sample data, or several series of sample data, should be stored in separate folders.  Developers should be aware of the fact that their updates will be temporary.  More stability in the testing environment is often required during integration and regression testing.  During that time, either the testing scripts can be updated with additional test cases, or simple held-off until completion of the testing phase.

Finally, in order to quickly execute the mass of scripts, a deployment or “make” script should be developed.  This could be either a PowerShell or command file, and often a Windows port of Sed/Awk can be very handy for database target substitutions.

Using an automated, iterative database development methodology can help reduce development time, bring Agile concepts to the database space, help integrate with version control, and improve code quality by reducing errors during synchronization with deployment targets.  Although it adds a little structural overhead during the initial development, this technique often pays back dividends during the testing, deployment, and maintenance phases of the software project.

SQL Server Software Development Chicago

Written by Andrew Palczewski

About the Author
Andrew Palczewski is CEO of apHarmony, a Chicago software development company. He holds a Master's degree in Computer Engineering from the University of Illinois at Urbana-Champaign and has over ten years' experience in managing development of software projects.
Google+

RSS Twitter LinkedIn Facebook Email

3 thoughts on “SQL Server Development Tips – Automated, Incremental Builds”

  1. You are correct it is very important (especially for a custom software development company) to have a good documentation and a track record of database changes that go with software updates. Our approach for smaller updates related to MS SQL Server database is to make the modifications on the development database and when we are ready to go live, use Red Gate software to build an incremental update SQL script. This script can be stored as a documentation of the changes and what is more important to run against production database to implement the changes.

    1. Man Interested Hi, i read your blog from time to time and i own a similar one and i was just wnnierdog if you get a lot of spam responses? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it’s driving me insane so any help is

  2. It’s not my first time to pay a visit this website,
    i am visiting this site dailly and get fastidious facts from here all the time.

Leave a Reply

Your email address will not be published. Required fields are marked *