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 7: Maintaining a Code Library<br />

The previous chapter took a practical look at how proper code reuse could reduce the<br />

number of bugs in our code, and greatly ease the team development process. It considered<br />

specific examples of the types of code modules (stored procedures versus UDFs, and so<br />

on) that best promote reuse.<br />

The scale of code reuse can vary, from full enterprise utilities, to useful, reusable<br />

functions (see, for example, Inside T-<strong>SQL</strong> Querying by Itzik Ben-Gan, where he creates<br />

a function, fn_nums, which creates a table of numbers, of varying size, which can be<br />

used anywhere), to small snippets of code that can be reused inside other modules to<br />

standardize the approach to common problems such as error handling.<br />

There are several difficult aspects to building and maintaining a code library. First, you<br />

have to create a place to store the information; you need to write the code in such a way<br />

that it can be reused, and you have to validate that it's going to do what you need it to do,<br />

every time. This chapter will cover a range of ways to generate, test, and share a library<br />

of code modules and snippets amongst the development team, covering the use of SSMS<br />

templates, text editors, wikis, and <strong>SQL</strong> Prompt. Text editors and wikis bring to the table<br />

powerful search capabilities, but at the expense of needing to store the code outside of<br />

the normal development environment. SSMS templates and <strong>SQL</strong> Prompt offer the ability<br />

to generate, find, and edit your code directly from a query window, which is probably the<br />

best mechanism for ensuring code reuse throughout the enterprise.<br />

199

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

Saved successfully!

Ooh no, something went wrong!