Question : How do I release unused space from a single table in SQL Server?

The production DB is on a SQL Server 2000 box, but all this was done on a backup that I restored to a SQL Server 2005 box.

I have a table that stores images (we'll call it img_table) that shows this when I run sp_spaceused:
Reserved:  105.7GB
Data: 8.4GB
Unused: 97.3GB
Index_Size: 40KB

Right now the DB's total size is 130GB.  If I could trim that down to 33 by cleaning up this table it might provide a nice performance increase or at the very least make maintenance less of a headache.

I spent several hours looking around Google and this site for a way to bring this down to a more manageable size.  I found a ton of different suggestions but none of them worked.  Here's what I've tried so far: (syntax might be a bit off, but I did eventually get all these to go through without errors)

I ran sp_help and noted that there was a clustered index for the table called PK_img_table since the table has a primary key.

I ran DBCC SHOWCONTIG (img_table,PK_img_table) and saw a lot of logical fragmentation in the index.

I ran DBCC INDEXDEFRAG (DBName, 'img_table', 'PK_img_table') and the index size went down to 40k from 800k, but the unused was pretty much unchanged.  DBCC SHOWCONTIG shows 0% logical fragmentation now.

So I ran DBCC DBREINDEX ('img_table', 'PK_img_table')  and not much happened.  I think the reserved, data, and unused went up or down by a few KB each.

Next I ran DBCC CLEANTABLE ('DBName', 'img_table') and again not much happened.

I tried dropping the index and recreating it, then going through all the above steps, but there's still 97GB of unused space.

I tried running a SHRINK command on the DB but the log file quickly filled up the disk.  I've thought about trying it again with recovery model on simple but haven't yet.

I thought about trying SELECT * INTO img_table2  FROM img_table and seeing if the copied table was smaller but I don't have enough free space on my drive for it.

Does anybody have any ideas, or is there a valid reason it should be acting like this?

Thanks in advance!

Answer : How do I release unused space from a single table in SQL Server?

Thanks,

Was kind of hoping to see column types,

That is not sounding good at all... Especially with the Vendor feedback... Imagess can be strange beasts, jpg for example is more of a compression technology, compare to Gif which is a reduce colour / bitmap, compare to bitmap which is a native image technology and then there is TIFF - tagged image so it was largely self explanatory and protable, but with sooooo  many different tags and options, there is probably not 1 system that could read every different possible tiff file. Good news is that up until Tiff 4.0 they were 'only' 2 gig maximum size... But they are always bloated, and built in compression is almost non-existant - it is most typically a 'lossless' format. As you can tell I am not a big fan of TIFF, and know that there are plenty out there who are - (and if reading this, don't bother telling me). TIFF is designed to be a superset of existing image file formats for desktop scanners (and paint programs and anything else that produces images with pixels in them) and will be enhanced on a continuing basis as new capabilities arise - and there in lies it's first big problem. Second, there is a lot of text in there with fields used to describe lots of information - hence tagged image. It is that complete set of fields that does / can change that leads to the compatiability problems.

Put in the hands of novices, or specialists  (used to starting at a resolution of 1200dpi), TIFF files can be huge. If that is what is in your database, then there is a bit of whitespace that quite possibly sp_spaceused is not calculating correctly.

One thing you could do is optimise and reload the images... But if they are ultimately going to be external, then there is probably little point in the short term to solve your problem (should be addressed longer term though).

Any way, if you could still get thos column types, and maybe a sample image, I wouldn't mind playing and checking the sp_spaceused calculations...



Random Solutions  
 
programming4us programming4us