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 10: Automating CRUD<br />

'UNIQUE_CONSTRAINT', 'USER_TABLE', 'VIEW' )<br />

AND ep.value IS NULL<br />

UNION ALL – -what about the database itself?<br />

SELECT Description ,<br />

undocumented<br />

FROM ( SELECT 'DATABASE' AS Description ,<br />

DB_NAME() AS undocumented<br />

) f<br />

LEFT OUTER JOIN sys.extended_properties ep ON ep.major_ID = 0<br />

AND minor_ID = 0<br />

WHERE value IS NULL<br />

UNION ALL – – what about parameters to stored procedures<br />

SELECT 'PARAMETER' ,<br />

DB_NAME() + '.' + Object_Schema_name(p.[object_id]) + '.'<br />

+ OBJECT_NAME(p.[object_id]) + '(' + p.name + ')'<br />

FROM sys.parameters p<br />

LEFT OUTER JOIN sys.extended_properties ep ON p.object_id = ep.major_ID<br />

AND minor_ID = p.parameter_ID<br />

WHERE parameter_ID > 0<br />

AND ep.value IS NULL<br />

UNION ALL – -or indexes? A little documentation, surely?<br />

SELECT 'INDEXES' ,<br />

DB_NAME() + '.' + Object_Schema_name(i.[object_id]) + '.'<br />

+ OBJECT_NAME(i.[object_id]) + '(' + i.name + ')'<br />

FROM sys.objects O<br />

INNER JOIN sys.indexes i ON O.object_id = i.object_id<br />

LEFT OUTER JOIN sys.extended_properties ep ON i.object_id = ep.major_ID<br />

AND minor_ID = i.index_ID<br />

WHERE index_ID > 0<br />

AND ep.value IS NULL<br />

AND O.Type_desc IN ( 'USER_TABLE', 'VIEW' )<br />

AND OBJECT_NAME(i.[object_id]) NOT LIKE 'sys%'<br />

Listing 10-1: Which database objects have no documentation stored in extended properties?<br />

Some programmers will find automated ways of filling in the extended properties, which<br />

will entirely defeat our attempts to extract and use meaningful documentation. Even<br />

AdventureWorks is not immune; try running Listing 10-2 against that database.<br />

296

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

Saved successfully!

Ooh no, something went wrong!