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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2: Documenting your Database<br />

down in front of some convoluted code, asked the rhetorical question, "God, what idiot<br />

wrote this code?" only to find out it was me, some time in the past. By documenting, I<br />

don't just mean the liberal sprinkling of inline comments to explain particular sections of<br />

code. If you are coordinating a number of programmers on a project, then it is essential<br />

to have more than this; you'll require at least an explanation of what it does, who wrote it<br />

or changed it, and why they did so. I would never advocate presenting the hapless coderefactorer<br />

with a sea of green, but with a reasonable commentary on the code to provide<br />

enough clues for the curious. I'd also want examples of use, and a series of assertion tests<br />

that I can execute to check that I haven't broken anything. Such things can save a great<br />

deal of time.<br />

Where the Documentation Should Be Held<br />

Most database developers like to keep the documentation for a database object together<br />

with its build script, where possible, so that it is easy to access and never gets out of<br />

synchronization. Certain information should be held in source control, but only<br />

sufficient for the purposes of continuous integration and generating the correct builds<br />

for various purposes. This is best done by an automatic process from the main source of<br />

the documentation. This primary source of the essential documentation should be, in<br />

effect, stored within the database, and the ideal place is usually within the source script.<br />

Source control cannot take away this responsibility from the developer. In any case,<br />

source control, as devised for procedural code, doesn't always fit perfectly with database<br />

development. It is good practice to store the individual build scripts in source control,<br />

and this is essential for the processes of configuration management, but it doesn't provide<br />

everything that's required for the day-to-day work of the database developer.<br />

The obvious place to hold documentation is in a comment block in the actual text for<br />

routines such as stored procedures, rules, triggers, views, constraints, and functions.<br />

This sort of comment block is frequently used, held in structured headers that are<br />

normally placed at the start of a routine, but acceptable anywhere within it. Microsoft<br />

38

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

Saved successfully!

Ooh no, something went wrong!