473,408 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

SQL2005 Rebuild Index Not Working

After rebuilding an index, it still shows as the same amount of
fragmentation. ANy ideas what's wrong?

I'm determining which indexes to rebuild using the following query:

SELECT
OBJECT_NAME(i.object_id) AS TableName,
i.name AS IndexName,
ips.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL,
'DETAILED') ips
JOIN sys.indexes i ON
i.object_id = ips.object_id
AND i.index_id = ips.index_id
WHERE ips.avg_fragmentation_in_percent > 10

(I know 10% is not enough where a full rebuild is called for, just
wanted to see my fragmentation)

Then I rebuild w/:

ALTER INDEX IX_CustomerName ON Customers REBUILD

When I rerun the 1st query the same amount of fragmentation is shown
as before the rebuild. I'd appreciate any help.

Jun 9 '06 #1
10 8849
Have you checked the fillfactor defined for these indexes?

(use sys.indexes to get this information)

wa********@yahoo.com wrote:
After rebuilding an index, it still shows as the same amount of
fragmentation. ANy ideas what's wrong?

I'm determining which indexes to rebuild using the following query:

SELECT
OBJECT_NAME(i.object_id) AS TableName,
i.name AS IndexName,
ips.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL,
'DETAILED') ips
JOIN sys.indexes i ON
i.object_id = ips.object_id
AND i.index_id = ips.index_id
WHERE ips.avg_fragmentation_in_percent > 10

(I know 10% is not enough where a full rebuild is called for, just
wanted to see my fragmentation)

Then I rebuild w/:

ALTER INDEX IX_CustomerName ON Customers REBUILD

When I rerun the 1st query the same amount of fragmentation is shown
as before the rebuild. I'd appreciate any help.


Jun 9 '06 #2
The Fill_factor is 0 on all my indexes, however I must admit I don't
know what fill factor really means.

Jun 9 '06 #3
Fill Factor - please look this up in Books online.

-------
From BOL: The fill factor option is provided for fine-tuning index data storage
and performance. When an index is created or rebuilt, the fill factor
value determines the percentage of space on each leaf level page to be
filled with data, therefore reserving a percentage of free space for
future growth. For example, specifying a fill factor value of 80 means
that 20 percent of each leaf-level page will be left empty providing
space for index expansion as data is added to the underlying table.

The fill factor value is a percentage from 1 to 100. The server-wide
default of 0 is the optimal choice in the majority of situations. When
fill factor is set to 0, the leaf level is filled almost to capacity,
but some space remains for at least one additional index row. With this
setting, the leaf level space is used efficiently, but room remains for
limited expansion before the page must be split.

Note:
Fill factor values 0 and 100 are the same in all respects.
-------

Not sure why the fragmentation still shows the same. After the
rebuild, can you run the following and the the first SELECT query again
see if the fragmentation has changed? (This is a very resource
intensive operation).

UPDATE STATISTICS Customers WITH FULLSCAN

wa********@yahoo.com wrote: The Fill_factor is 0 on all my indexes, however I must admit I don't
know what fill factor really means.


Jun 9 '06 #4
Thanks for the info.

After running UPDATE STATISTICS.

I still received the same results from my 1st query (although I noticed
it took signifigantly longer to run on the 1st attempt after running
UPDATE STATISTICS.

I still have an index at 83.3333333333333 fragmentation. It's wierd.

Jun 9 '06 #5
Do you have clustered indexes on the tables? They won't be defragmented
without them.

Jackie
<wa********@yahoo.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Thanks for the info.

After running UPDATE STATISTICS.

I still received the same results from my 1st query (although I noticed
it took signifigantly longer to run on the 1st attempt after running
UPDATE STATISTICS.

I still have an index at 83.3333333333333 fragmentation. It's wierd.

Jun 9 '06 #6
Every table has a primary key which I believe (correct me if I'm wrong)
would give them a clustered Index.

Jun 9 '06 #7
(wa********@yahoo.com) writes:
Every table has a primary key which I believe (correct me if I'm wrong)
would give them a clustered Index.


By default, when you create a primary key, this results in a clustered
index. However, that does not mean that just because there is a PK,
that there is a clustered index on the table, as the PK can deliberately
have been created as non-clustered.

(And in many cases, clustering on the PK is not the best choice.)

As for your original question, am I right to suspect that the table
in question is fairly small? If there is only data for 1½ index page,
there will be some free space that will look like fragmentation.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 9 '06 #8
I understand your point Erland, but these Primary keys were created w/o
specifying that they should be non-clustered, so I'm certain they are.
Why is it that w/o a clustered index defragmentation on non-clustered
indexes can't occur, or did I misunderstand the previous poster?

You are correct that these tables currently are small by most people's
standards. I'm guessing that the largest one has < 1000 records. Is it
mentioned somewhere in SQL books on-line about free space looking lile
fragmentaion, that I can read up on?

Also, I'm looking for a good SQL Server 2005 book, if anyone has a
recommendation I'd apreciate it. I'm an experienced programmer, but am
not an experienced DBA as far as actually creating and managing tables,
views, and indexes, etc. inteligently. I've usually just written
queries or stored procs that end up getting used in my frontend
programs that interact w/ an existing database someone else had
created.

A book that was more beginner DBA orientated I think would be helpful
to me. Thanks for your input everyone.

Jun 11 '06 #9
(wa********@yahoo.com) writes:
I understand your point Erland, but these Primary keys were created w/o
specifying that they should be non-clustered, so I'm certain they are.
You can always use sp_helpindex to find out.
Why is it that w/o a clustered index defragmentation on non-clustered
indexes can't occur, or did I misunderstand the previous poster?
I don't recall exactly what he said, but you can't defragment the data
pages without a clustering index. The NC indexes are defragmentable
nevertheless.
You are correct that these tables currently are small by most people's
standards. I'm guessing that the largest one has < 1000 records. Is it
mentioned somewhere in SQL books on-line about free space looking lile
fragmentaion, that I can read up on?


Let me put it this way: with tables of that size, there's usually not
much reason to worry about fragementation anyway.

Fragmentation matters when it results in data being spread out on
many extra pages. Say that you have a table with 1 GB of data. If
the data pages are only 50% full, the server needs to read 2 GB of
disk to scan all data. This can affect the performance of the system.

Whether this is spelt out in clear in Books Online, I don't know. But
you can read about the physical architecture starting on
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/33572c3b-343d-45aa-bb42-1d31423ae5cc.htm.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 11 '06 #10
Yeah, I was just testing the rebuild process to see that it was
sucessful in correcting fragmentation in the event it became necessary
as well as to add the process into a maintenance plan.

Hopefully this behavior I'm experiencing is like you said, because of
the small amount of data present, as no one else seems to have posted
similar problems.

Thank you for your assistance. I appreciate you sharing your time and
experience.

Jun 12 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: r1100r98 | last post by:
I am having a problem moving the data from a datatable to the SQL2005 table (using VB2005). See code below. The SQL2005 table is empty, the datatable is being filled from a text file, not from...
5
by: Mike | last post by:
I'm having trouble accessing SQL2005 Standard Edition as a second instance of SQL Server where the first instance is SQL 2000 Enterprise Edition. I installed SQL 2005 as a named instance...
8
by: Radu | last post by:
Hi. This code worked fine with SQL2005, but has a problem with SQL2000.... Which one ???? cnSQL = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))...
7
by: Earl | last post by:
Can anyone point me to some good references for coding a Winforms app to trigger replication (merge preferably) on SQL2005? I'm setting up a scenario where I want my app to allow multiple laptops...
3
by: Michael Schöller | last post by:
Hello, First of all english is not my natural language so please fogive me some bad mistakes in gramatic and use of some vocables :). I have a great problem here. Well I will not use it...
0
debasisdas
by: debasisdas | last post by:
This code genenates a script to rebuld all the indexes with height greater than 3 for all the users except for SYS user. The script needs to be executed from SYS schema. This can also be executed...
0
by: =?Utf-8?B?U1VOTlk=?= | last post by:
Hi, i am uploading a .docx file into sql2005 and later when i retrieve the file from the database and i open it, i get a error message "The file is corrupted and cannot be open". I am not facing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.