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 8: Exploring your Database Schema<br />

SUM(OBJECTPROPERTY(s.object_ID, 'IsDefaultCnst')) AS [DefCns] ,<br />

SUM(OBJECTPROPERTY(s.object_ID, 'IsForeignKey')) AS [Fk] ,<br />

SUM(OBJECTPROPERTY(s.object_ID, 'IsConstraint')) AS [Cnstrnt] ,<br />

SUM(OBJECTPROPERTY(s.object_ID, 'IsDefault')) AS [Default] ,<br />

SUM(OBJECTPROPERTY(s.object_ID, 'IsTrigger')) AS [Trigger]<br />

FROM sys.objects S – -to get the objects<br />

INNER JOIN sys.objects p – -to get the parent object<br />

– -and then the name of the table<br />

ON s.parent_Object_ID = p.[object_ID]<br />

WHERE OBJECTPROPERTY(p.object_ID, 'IsTable') 0<br />

GROUP BY DB_NAME() + '.' + Object_Schema_name(s.[object_ID]) + '.' + p.name<br />

Listing 8-9: How many of each object?<br />

Too many indexes…<br />

By a slightly different route, we can also find out which of our tables have the most<br />

indexes on them. Are any of them duplications? For example, you might use the query in<br />

Listing 8-10 to see where indexes have gathered in undue numbers.<br />

238

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

Saved successfully!

Ooh no, something went wrong!