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.

275<br />

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

At some point, someone decided to use the special value of 0 to denote the description of<br />

the type, which you can see from …<br />

SELECT name,* FROM master.dbo.spt_values WHERE number=0 ORDER BY type<br />

… but the scheme soon fell foul of the fact that some enumerations, such as binary<br />

'Yes'/'No', required a zero!<br />

Using System Tables (pre-<strong>SQL</strong> 2005)<br />

If you are stuck on <strong>SQL</strong> <strong>Server</strong> 2000 or older, this shouldn't stop you dead in your tracks,<br />

because there are still ways to get at this metadata. Instead of using the catalog views, you<br />

have to use the system tables. The mapping between the system tables and the system<br />

catalog views are all listed for you on Books Online. The big problem is that the code is<br />

complicated by the fact that each routine is stored in as many NVARCHAR(4000) chunks<br />

as are required to hold the entire definition. A solution that I use for searching through<br />

the definitions of routines in <strong>SQL</strong> <strong>Server</strong> 2000 database is given at www.simple-talk.<br />

com/community/blogs/philfactor/archive/2006/06/03/854.aspx.<br />

Using SSMS to Explore Table Metadata<br />

Using some of the previously-presented scripts, and a little ingenuity, we can use SSMS<br />

to do a detailed exploration of the metadata of our routines and tables. To provide a feel<br />

for the sort of magic that is possible, let's start with a brief demo. I have a blank query<br />

window. I wonder what tables I have in my database and what they're for. I hit my query<br />

shortcut, CTRL+6. The output shown in Figure 9-4 appears in the results pane.

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

Saved successfully!

Ooh no, something went wrong!