C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
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
8y
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:
SQL Table
SQL
Fragmentation Percent
Recommended related topics
Membership not found