For clarity, I meant tables with clustered indexes.
Main Topics
Browse All TopicsHi,
What should be the command for me to check index or table fragmentation ? how about to rebuild it ?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The first part of your question has been answered by alpmoon - optdiag is the best and easiest way to see fragmentation. I would also look at "Data Page Cluster Ratio" for your table, which is a good measure of fragmentation.
You can also ask this question directly within ASE by using the "derived_stat" function - if you're using ASE 12.5.3 or above:
select derived_stat([object_name]
This will give you the data page cluster ratio for a specific index id - use indid 0 for a table without a clustered index, and indid 1 for a table with.
If the DPCR is below 0.9 then there may be benefit in defragmenting the table.
You can do this either by dropping & recreating the clustered index (if there is one), or adding a dummy clustered index and then dropping it again (if there isn't), or by running "reorg rebuild" (if the table is DOL; data-only locked, ie datapages or datarows locking).
All of these methods lock the table exclusively while they run. The first two need free space in your database equal to about 120% the size of the table; the third method only works on DOL tables and needs the "select into" option enabled for that database - which in turn disables the ability to take transaction dumps until you run a full dump database again.
You should carefully plan when you run these activities. Most sites would run these monthly or even quarterly. Some never defragment at all but that is a mistake I think...
Business Accounts
Answer for Membership
by: alpmoonPosted on 2009-09-10 at 23:34:06ID: 25307074
For clustered tables, you can use optdiag to see space utilization.
column]]]] [-o output_file] }
Basic syntax:
optdiag statistics
database[.owner[.[table][.
[-U username] [-P password]
Space utilization
Space utilization uses the average row size and number of rows to compute the expected minimum number of data pages, and compares it to the current number of pages. If space utilization is low, running reorg rebuild on the table or dropping and re-creating the clustered index can reduce the amount of empty space on data pages, and the number of empty pages in extents allocated to the table.
If you are using space management properties such as fillfactor or reservepagegap, the empty space that is left for additional rows on data pages of a table with a clustered index and the number of empty pages left in extents for the table affects the space utilization value.
If statistics have not been updated recently and the average row size has changed or the number of rows and pages are inaccurate, space utilization may report values greater than 1.0.