views:

191

answers:

3

I have a SQL 2005 database with one large table. I have ran a DELETE to prune some items from the table and I want to free the space back to the OS.

I have tried the following commands

DBCC SHRINKDATABASE (MyDB, TRUNCATEONLY);
DBCC SHRINKFILE (MyTable, TRUNCATEONLY);

and I have also rebuilt the clustered index with the following command

ALTER INDEX [IX_Clustered] ON [dbo].[MyTable] REBUILD WITH ( PAD_INDEX  = ON, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF )

The SHRINK commands had no effect and the index rebuild increased the database size by 35GB (the database is 1.5TB).

So, I'm at a loss. What do I need to do to regain unused database space?

Edit: The log file is not the problem. The main database .MDF file it too large.

Edit 2: Here is the results of *sp_spaceused MyTable*:

rows        reserved           data               index_size         unused
----------- ------------------ ------------------ ------------------ ------------------
1031649352  1543899648 KB      1481718624 KB      54444664 KB        7736360 KB
A: 

Have you checked your log file size? Have you tried spaceused to see whether the table is still / indices are still occupying a lot of space?

Adamski
It is on a different drive and not causing a problem. Only the .MDF file is too big.
Mr. Flibble
OK - Have you tried spaceused <Table> to see whether the table is still / indices are still occupying a lot of space?
Adamski
I did that now and added the results to the question.
Mr. Flibble
+1  A: 

Try re-indexing using DBREINDEX, updating the stats, then shrinking, I think that did the trick for me.

DBCC DBREINDEX ('?', ' ', 80)
GO
EXEC sp_updatestats
GO
Alex Black
Also, have you tried using the Shrink Database commands from the UI?
Alex Black
The DBCC DBREINDEX ('?', ' ', 80) command caused 70gb .MDF file growth and failed :(
Mr. Flibble
That doesn't sound promising :) Did you replace ? with your table name? using DBCC_DBREINDEX worked for me. I had a large database from which I deleted 90% of the data, and once I ran DBCC_DBREINDEX and THEN shrink, its data size went down to where it should be.
Alex Black
A: 

did you delete LOB data, ie TEXT, NTEXT, IMAGE or XML datatypes?

sometimes you need to rebuild tables to reclaim the space if you have deleted LOB data.

Actually, having just looked at your figures - 99% of the space is taken up by data+index - where is the free space you are trying to reclaim?

Kev Riley