SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Index fregment doesn't come to 0


Index fregment doesn't come to 0

Author
Message
KcV
KcV
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 222
Hi,

I have just shifted my database of sql 2000 to sql 2008 64 bit after running Upgrade adviser.
then i run DBCC DBREINDEX in all tables.

After that when i checked manually then i found that about 80 % tables are well fragmented having 0 logical fragmentation but rest 20 % tables ware having fragmentation of 40 %,50 %,80 %,99 %.

why it is so high ?

after doing manual re-indexing and re-organizing 2 to 5 times , it is not coming to 0 %.

why this is happening ?

pls help.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64033 Visits: 18570
What is the size of some of these tables? How many pages? Is there a Clustered Index on the tables in question?



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

KcV
KcV
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 222
First of all thanks for reply.

What is the size of some of these tables?
- some of tables are having 100 to 2000000 rows

How many pages?
- i don't know about pages. actually i don't know how to see it. where i can find it ?

Is there a Clustered Index on the tables in question?
- Yes, there are clustered indexes and non clustered too.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64033 Visits: 18570
What is the query you are using to determine fragmentation?



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

KcV
KcV
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 222
Here sp,

ALTER Procedure [dbo].[DBA_DBCC_DBREINDEX_UPDATESTAT]

As

BEGIN
---- Set Recovery Mode SIMPLE
Begin
ALTER DATABASE aaa
SET RECOVERY SIMPLE;
End

---- Re-Indexing of all tables of Database
Begin
declare @tabName sysname, @schname sysname
--declare cur_index cursor for select s.name, t.Name from Sys.Tables t inner join sys.schemas s on t.schema_id = s.schema_id order by t.Create_Date -- for 2005
declare cur_index cursor for SELECT sysusers.name,sysobjects.name FROM sysobjects INNER JOIN sysusers ON sysobjects.uid = sysusers.uid where sysusers.name='dbo' and xtype ='U' order by sysobjects.crdate -- for 2000

Open cur_index
fetch next from cur_index into @schname, @tabname
while @@Fetch_status = 0
begin
print ('DBCC DBREINDEX (['+ @schname + '.'+ @tabname +'])')
exec('DBCC DBREINDEX (['+ @schname + '.'+ @tabname +'])')
fetch next from cur_index into @schname,@tabname
end
Close cur_index
deallocate cur_index
EXEC sp_updatestats
End

---- Set Recovery Mode FULL

Begin
ALTER DATABASE aaa
SET RECOVERY FULL;
End
END
GilaMonster
GilaMonster
SSC Guru
SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)

Group: General Forum Members
Points: 213269 Visits: 46259
First problem

KcV (1/5/2013)

---- Set Recovery Mode SIMPLE
Begin
ALTER DATABASE aaa
SET RECOVERY SIMPLE;
End


Breaking the log chain, preventing any point in time restores until the DB is switched back to full and a full or diff backup is taken, plus means that log backups can't restore over this time. This is not a good idea

---- Re-Indexing of all tables of Database
<nip>


So where do you check fragmentation? Looks like a blanket rebuild of everything, whether it needs rebuilding or not.

May I suggest you replace that with one of these:
http://ola.hallengren.com/Versions.html
http://sqlfool.com/2011/06/index-defrag-script-v4-1/

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)

Group: General Forum Members
Points: 51176 Visits: 17653
KcV (1/4/2013)
Hi,

I have just shifted my database of sql 2000 to sql 2008 64 bit after running Upgrade adviser.
then i run DBCC DBREINDEX in all tables.

After that when i checked manually then i found that about 80 % tables are well fragmented having 0 logical fragmentation but rest 20 % tables ware having fragmentation of 40 %,50 %,80 %,99 %.

why it is so high ?

after doing manual re-indexing and re-organizing 2 to 5 times , it is not coming to 0 %.

why this is happening ?

pls help.

can you post the fragmentation results please?

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64033 Visits: 18570
Perry Whittle (1/5/2013)
KcV (1/4/2013)
Hi,

I have just shifted my database of sql 2000 to sql 2008 64 bit after running Upgrade adviser.
then i run DBCC DBREINDEX in all tables.

After that when i checked manually then i found that about 80 % tables are well fragmented having 0 logical fragmentation but rest 20 % tables ware having fragmentation of 40 %,50 %,80 %,99 %.

why it is so high ?

after doing manual re-indexing and re-organizing 2 to 5 times , it is not coming to 0 %.

why this is happening ?

pls help.

can you post the fragmentation results please?


I'd still like to see the query that is used to get the fragmentation.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

KcV
KcV
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 222
there is no query to see fragmentation.

i used to see it in index --> rebuild or index -- > reorganize options.
KcV
KcV
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 222
thanks man, for giving me such a wonderful code.

I didn't try yet but i think this is the solution of my problem. (in working hours i can't run this sp)

i will let you know the result.

thanks again
:-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search