30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7: Maintaining a Code Library<br />

Text editors<br />

Since T-<strong>SQL</strong> code is just text, a primitive way of maintaining a code library would be<br />

simply to store all your snippets in a text file. The relevant snippet could be retrieved by<br />

a search on its assigned name, and then copied and pasted into your <strong>SQL</strong> code. This is<br />

a very labor-intensive and error-prone approach, so if you do go down this route, it's at<br />

least worth investing in a decent text editor that will provide some mechanism for<br />

managing the process.<br />

Many modern text editors have built-in mechanisms for maintaining code snippets. For<br />

example, EditPlus, one of the better-known shareware text editors, provides the cliptext<br />

feature which allows us to create and store our own library of code snippets. It works like<br />

the clipboard in Office, but has persistence to permanent storage. The library is stored as<br />

a file, which means that it can be edited directly and, more importantly, can be checked<br />

into source control, in order to maintain different versions of the file, and to share it with<br />

other developers and DBAs within the organization.<br />

Testing such a file is more challenging. As was suggested earlier, individual files can be<br />

validated using individual, customized tests. A large single file, possibly containing a mix<br />

of snippets as well as full templates, will require a fairly sophisticated testing mechanism.<br />

It might help to add, to the comment header section for each piece of code, a description<br />

of the test for that code, although this still makes automated testing difficult.<br />

To create a new cliptext library, simply navigate to the cliptext window, on the left-hand<br />

side of the EditPlus screen, right-click on the drop down and select New.<br />

214

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!