12Mar/090
PoTW Webcast Materials
For those interested, here's the links I mentioned during my presentation:
... and here's the scripts that I used during my presentation:
Use sandbox; Go /* Create a table to promote fragmentation */ Create Table dbo.fragmented ( myGuid uniqueidentifier Not Null Constraint PK_fragmented Primary Key Clustered (myGuid) ); /* Populate our table */ Set NoCount On; Declare @iterations int = 0; While @iterations < 250000 Begin Insert Into dbo.fragmented Select NewID(); Set @iterations += 1; End; /* Verify the number of records in our table */ Execute sp_spaceused 'dbo.fragmented'; /* Let's take a look at sys.dm_db_index_physical_stats */ Select Object_Name(ddips.object_id) As 'tableName' , i.name As indexName , ddips.* From sys.dm_db_index_physical_stats (DB_ID(), Object_ID(N'fragmented'), NULL, NULL , 'DETAILED') As ddips Join sys.indexes As i On ddips.object_id = i.object_id And ddips.index_id = i.index_id; Select * From sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(N'fragmented'), NULL, NULL , 'LIMITED'); /* ShowContig should return us the same information */ DBCC ShowContig ('fragmented'); /* ExtentInfo is an undocumented command that will show us the number of allocated extents */ DBCC ExtentInfo (0, 'fragmented', 1); /* Grab our page number */ SELECT OBJECT_NAME(p.OBJECT_ID) AS 'tableName' , i.name AS 'indexName' , p.partition_number , au.type_desc , CONVERT (VARCHAR(6), CONVERT (INT, SUBSTRING (au.first_page, 6, 1) + SUBSTRING (au.first_page, 5, 1))) + ':' + CONVERT (VARCHAR(20), CONVERT (INT, SUBSTRING (au.first_page, 4, 1) + SUBSTRING (au.first_page, 3, 1) + SUBSTRING (au.first_page, 2, 1) + SUBSTRING (au.first_page, 1, 1))) AS 'firstPage' , CONVERT (VARCHAR(6), CONVERT (INT, SUBSTRING (au.root_page, 6, 1) + SUBSTRING (au.root_page, 5, 1))) + ':' + CONVERT (VARCHAR(20), CONVERT (INT, SUBSTRING (au.root_page, 4, 1) + SUBSTRING (au.root_page, 3, 1) + SUBSTRING (au.root_page, 2, 1) + SUBSTRING (au.root_page, 1, 1))) AS 'rootPage' , CONVERT (VARCHAR(6), CONVERT (INT, SUBSTRING (au.first_iam_page, 6, 1) + SUBSTRING (au.first_iam_page, 5, 1))) + ':' + CONVERT (VARCHAR(20), CONVERT (INT, SUBSTRING (au.first_iam_page, 4, 1) + SUBSTRING (au.first_iam_page, 3, 1) + SUBSTRING (au.first_iam_page, 2, 1) + SUBSTRING (au.first_iam_page, 1, 1))) AS 'firstIAM_page' FROM sys.indexes AS i JOIN sys.partitions AS p ON i.OBJECT_ID = p.OBJECT_ID AND i.index_id = p.index_id JOIN sys.system_internals_allocation_units AS au ON p.hobt_id = au.container_id WHERE OBJECT_NAME(p.OBJECT_ID) = 'fragmented' ORDER BY tableName; /* View our pages */ DBCC TraceOn (3604); DBCC Page (sandbox, 1, pageNumberHERE, 3); DBCC TraceOff (3604); /* Rebuild our index */ Alter Index PK_fragmented On dbo.fragmented REBUILD; /* Clean-Up! */ Drop Table dbo.fragmented;
Thank you for watching the webcast!
Michelle
Source: http://sqlfool.com/2009/03/potw-webcast-materials/
Tagged as: PoTW, webcast
Leave a comment
Categories
- Business Intelligence
- Internals
- Miscellaneous
- PASS
- Performance & Tuning
- Presentations
- SQL 2008
- SQL Tips
- Syndication
- T-SQL Scripts
Subscribe to my blog!
| Like what you see? Subscribe! |
![]() |
Around the Web
Recent Tweets
- @gregsohl yeah, that would be a nice feature. Did you find any products that do support field-level dependencies?
- @MladenPrajdic @atlantis_uk Thanks, Mladen, I'll be sure to check that out. :)
- I'm really lovin' @RedGate's #SQL Dependency Tracker. I can see it saving me a *lot* of time once I figure out what the heck I'm doing :)
Archives
- November 2011
- October 2011
- September 2011
- July 2011
- June 2011
- May 2011
- April 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- July 2010
- June 2010
- May 2010
- April 2010
- February 2010
- January 2010
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008


