Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBCC REINDEX question

Status
Not open for further replies.

katbear

Programmer
Mar 14, 2007
270
US
I just want to verify: Running DBCC REINDEX *only* works if the table has a CLUSTERED index, correct?

My testing shows that heap tables are not affected at all by reindexing.

Just want to confirm this!!
 
The DBCC REINDEX command has no effect on a heap table.
You can use one of three methods to rebuild a heap. ( a table without a clustered index.)
With the first method, you drop the nonclustered indexes and create a clustered index to order the data the way you want it. Then, you drop the clustered index and recreate the non-clustered indexes. With the second method, you use SELECT..INTO to make a copy of the heap, then either use sp_rename and reset your permissions to make the copy the primary heap table or truncate the table and use INSERT..SELECT to reinsert the data. The third method requires that you use BCP –N OUT (or another export method such as Data Transformation Services—DTS) to copy the data out of SQL Server, then truncate and reload the data.


- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Thanks Paul. I assume in the 2nd & 3rd methods, when you reinsert/load the data, you make sure you insert/load in the order you want?
 
Correct, you use an order by clause.

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top