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.

[Table_Name] ASC ,<br />

[Column_ID] ASC ,<br />

[Name] ASC<br />

Listing 2-10: Extracting documentation from columns.<br />

53<br />

Chapter 2: Documenting your Database<br />

For the rest of our database objects and routines, we can extract the contents of the<br />

header in a number of different ways. Listing 2-11 shows a stored procedure that does<br />

the job for any header. It will extract all headers in a routine, wherever they are in the<br />

code, and will add all the inline header material. It will work for any type of header that<br />

conforms to the /*** … */ (block comment) and – - – (inline) convention.<br />

CREATE PROCEDURE Header<br />

@RoutineCode VARCHAR(MAX) ,<br />

@header VARCHAR(MAX) OUTPUT<br />

/** summary: ><br />

takes a routine's definition and extracts all header information from it,<br />

including inline header information<br />

Revisions:<br />

– version : 1<br />

Modification: Created the procedure<br />

Author : Phil Factor<br />

Date : 15/12/2009<br />

– version : 2<br />

Modification: Added mod to allow for nested comment blocks.<br />

Author : Phil Factor<br />

Date : 16/12/2009<br />

example:<br />

– code: ><br />

Declare @Definition varchar(Max)<br />

Declare @Header Varchar(max)<br />

SELECT @Definition=Definition<br />

FROM sys.sql_modules AS sm<br />

JOIN sys.objects AS o ON sm.object_id = o.object_id<br />

where OBJECT_NAME(sm.object_id) = 'header'<br />

Execute header @Definition, @Header output<br />

Select @Header<br />

returns: the header block as an output variable<br />

*/<br />

AS

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

Saved successfully!

Ooh no, something went wrong!