SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How and when reindexing a db?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

fabianus76
Posting Yak Master

191 Posts

Posted - 08/16/2006 :  13:14:57  Show Profile  Reply with Quote
Hello guys,

Two things:

1) Could somebody explain me how to reindex all tables in my db?

2) How do I know when I should reindex my db?

Thank you very much for any help!

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !

spirit1
Cybernetic Yak Master

Slovenia
11751 Posts

Posted - 08/16/2006 :  13:20:48  Show Profile  Visit spirit1's Homepage  Reply with Quote
1. using DBCC DBREINDEX or DBCC INDEXDEFRAG or drop index create index or alter index statements
2. well run DBCC SHOWCONTIG to see how much fragmentation you have in your indexes. I defragment my indexes when the fragmentation reaches 10-20% based on the table.

some people have a scheduled job that rebuilds the indexes every day in low traffic hours.
SQL server 2005 has also improved greatly on live index rebuild.



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp

Edited by - spirit1 on 08/16/2006 13:21:53
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 08/16/2006 :  15:14:12  Show Profile  Reply with Quote
Thank you very much Spirit1. That's very useful for me.

Could you help me to interpreter the report for one of my tables:

DBCC SHOWCONTIG scanning 'cs_UserProfile' table...
Table: 'cs_UserProfile' (2114822596); index ID: 1, database ID: 18
TABLE level scan performed.
- Pages Scanned................................: 27
- Extents Scanned..............................: 6
- Extent Switches..............................: 19
- Avg. Pages per Extent........................: 4.5
- Scan Density [Best Count:Actual Count].......: 20.00% [4:20]
- Logical Scan Fragmentation ..................: 96.30%
- Extent Scan Fragmentation ...................: 83.33%
- Avg. Bytes Free per Page.....................: 5165.3
- Avg. Page Density (full).....................: 36.18%

The percentage you're talking about, is it the Logical Scan Fragmentation?

Thank you very much for your help!

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37133 Posts

Posted - 08/16/2006 :  15:14:59  Show Profile  Visit tkizer's Homepage  Reply with Quote
http://weblogs.sqlteam.com/tarad/archive/2006/04/11/9585.aspx

Tara Kizer
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 08/17/2006 :  08:39:49  Show Profile  Reply with Quote
Here is a nice way to reindex all tables :


USE DatabaseName --Enter the name of the database you want to reindex

DECLARE @TableName varchar(255)

DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName,' ',90)
FETCH NEXT FROM TableCursor INTO @TableName
END

CLOSE TableCursor

DEALLOCATE TableCursor


I found this here : http://www.sql-server-performance.com/rebuilding_indexes.asp

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000