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.

271<br />

Chapter 9: Searching DDL and Build Scripts<br />

code to give you the idea. The full code is available from the code download page for this<br />

book (see the Introduction).<br />

IF EXISTS ( SELECT *<br />

FROM information_Schema.routines<br />

WHERE specific_name = 'FindString' )<br />

DROP PROCEDURE FindString<br />

go<br />

CREATE PROCEDURE FindString<br />

/**<br />

summary: ><br />

This finds the string that you specify within the name of every database object<br />

including indices, agent jobs, extended properties and parameters of routines.<br />

It searches within the text (definition) for every routine, and within the value<br />

of every extended property. It displays the full path of the database object, the<br />

object type, the dates of creation and modification (sometimes that of the parent<br />

if this information isn't available) as well as the name of the parent of the<br />

object.<br />

example:<br />

– code: findstring '' – -list every object, along with creation date etc<br />

example:<br />

– code: findString 'GetDate'--find where the string 'getdate' appears!<br />

example:<br />

– code: findstring 'b[aeiou]t'--find but, bot,bit,bet and bat!<br />

returns: ><br />

Qualified_Name Varchar<br />

This is the fully-qualified name of the object so that you know where it lurks.<br />

Sometimes, the path is a bit artificial, but it should be obvious how the<br />

convention works.<br />

Object_Type Varchar<br />

A description of the type of object the string was found in. 'Definition' refers to<br />

the code within the routine.<br />

created DateTime<br />

The date that either the object or its parent was created.<br />

Last_Modified DateTime<br />

The date that either the object or its parent was last modified<br />

Parent Varchar<br />

The name of the parent of the object if known<br />

**/ @SearchString VARCHAR(2000)<br />

AS – ------------------------------------------------------------------------<br />

IF CHARINDEX('%', @SearchString) = 0 – -if user hasn't specifed search<br />

– -string in the <strong>SQL</strong> wildcard format.

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

Saved successfully!

Ooh no, something went wrong!