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
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
SQL Table Fragmentation Percent
WhatsApp
Ashish Srivastava
8y
4.1
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
Up Next
Create Table, Select, Insert, Update, Delete Table In SQL
Ebook Download
View all
Basics of SQL Server
Read by 1.5k people
Download Now!
Learn
View all
Membership not found