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 />

Coding for Reuse<br />

In this chapter, I'll present several techniques for promoting and managing the use<br />

of reusable code snippets and templates, using tools such as SSMS and <strong>SQL</strong> Prompt.<br />

However, before we examine these techniques, it needs to be emphasized that it's not<br />

enough to simply have snippets of code; you need to write these snippets so that they<br />

can easily be incorporated into your existing code, in such a way that anyone within the<br />

organization can, within reason, incorporate the code into almost any query. In order to<br />

make sure a script can be reused, and is reused appropriately, we need to understand what<br />

exactly that script does and how it's supposed to be used. This means that it needs to be<br />

well written and documented, and we need to be confident in the script, so it also needs<br />

to be well tested.<br />

If the code is incomplete and undocumented, you're assuming that everyone who uses it<br />

has a complete enough understanding of the appropriate use of the code for them to be<br />

able to apply it. Many, maybe even most, of your users will have the requisite knowledge,<br />

but far too many are unlikely to understand what they're supposed to do with your code.<br />

Keep this class of user in mind as you write and document the snippets that you're going<br />

to share. If you just think through how each snippet is likely to be used, you can decide if<br />

that snippet has been written in such a way that it can be reused.<br />

Code comments<br />

You need to have a defined process for marking any script that you intend for reuse. This<br />

will help you identify the script, and it will help you retrieve it, either from systems where<br />

it has been applied, or from the storage system you're using to keep it. It must be clear<br />

what your script is doing, when it was updated, what version it is, where it's used, how it's<br />

used, and so on.<br />

200

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

Saved successfully!

Ooh no, something went wrong!