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.

BEGIN CATCH<br />

IF @@TRANCOUNT > 0<br />

BEGIN<br />

ROLLBACK TRANSACTION<br />

END<br />

RETURN ERROR_NUMBER();<br />

END CATCH<br />

GO<br />

Listing 7-7: A customized stored procedure template.<br />

213<br />

Chapter 7: Maintaining a Code Library<br />

The key thing to remember, when customizing templates, is to strictly follow the<br />

format for creating template parameters, namely . You're not required to supply either the data type or the default value, but the<br />

parameter name must be identical everywhere it is referenced, or you'll simply create a<br />

new parameter. Notice, in Listing 7-7, that Procedure_Name is referenced more than<br />

once in the template definition.<br />

If you save these changes, the default template will be overwritten to reflect the standards<br />

you are attempting to implement within your enterprise. The modified template still<br />

retains the functionality of the standard templates; CTRL+SHIFT+M still works and you<br />

can fill in the parameter values as described earlier.<br />

Just as you can edit existing templates, you can also create multiple new templates for use<br />

within your system, storing them all within the Template Explorer, alongside the system<br />

templates. Again, you just need to be sure that you keep a backup of the system templates,<br />

and check all the templates into source control so that you can maintain versions and a<br />

known change history.<br />

While templates work well as a code generation and sharing mechanism for object<br />

creation scripts, you'll also need to create and maintain smaller snippets of code,<br />

such as the error handling routine shown earlier, and templates are not best suited<br />

for this. To maintain a listing of partial code snippets for reuse in multiple scripts,<br />

another mechanism is needed. One possibility is to use one of the advanced text<br />

editors, such as EditPlus.

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

Saved successfully!

Ooh no, something went wrong!