What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 6918 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > SQL Server > Identifying Fragmentation of Tables ...
PandianS

Identifying Fragmentation of Tables

 Code Snippet posted by: PandianS | Posted on: 5/11/2009 | Category: SQL Server Codes | Views: 1016 | Status: [Member] [MVP] | Alert Moderator   


DECLARE @DBID INT
SELECT @DBID = DB_ID()

--- Identifying the High / Low Fragmentation of Table(s) in the active Database
SELECT OBJECT_NAME(FRG.[OBJECT_ID]) 'TABLE NAME',INDEX_TYPE_DESC 'INDEX TYPE',IND.[NAME],CASE WHEN FRG.AVG_FRAGMENTATION_IN_PERCENT <30 THEN 'To Be Re-Organized' ELSE 'To Be Rebuilt' END 'ACTION TO BE TAKEN' ,FRG.AVG_FRAGMENTATION_IN_PERCENT '% FRAGMENTED'
FROM SYS.DM_DB_INDEX_PHYSICAL_STATS(@DBID, NULL, NULL, NULL, NULL) FRG JOIN SYS.SYSINDEXES IND
ON (IND.ID =FRG.[OBJECT_ID] AND IND.INDID = FRG.INDEX_ID)
WHERE FRG.AVG_FRAGMENTATION_IN_PERCENT > 0
AND FRG.DATABASE_ID = @DBID
AND IND.FIRST IS NOT NULL
AND IND.[NAME] IS NOT NULL
ORDER BY 5 DESC

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 12:11:56 AM