C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
SQL Table Fragmentation Percent
WhatsApp
Ashish Srivastava
9y
4.2
k
0
1
25
Blog
Query:
DECLARE
@
Database
NVARCHAR(128)
DECLARE
@
Table
NVARCHAR(128)
SET
@
Database
= N
'MYDATABASE'
-- Database
SET
@
Table
= N
'dbo.ProposalForm'
-- Table
SELECT
I.
name
,
ROUND(S.avg_fragmentation_in_percent, 2)
AS
FragmentationPercent
FROM
sys.dm_db_index_physical_stats (DB_ID(@
Database
), OBJECT_ID(@
Table
)
,
NULL
,
NULL
,
NULL
) S
INNER
JOIN
sys.indexes I
ON
S.object_id = I.object_id
AND
S.index_id = I.index_id
Output:
People also reading
Membership not found