September 17, 2009 at 7:39 am
is your post incomplete? what is the query?
September 17, 2009 at 8:25 am
I"m thinking you had a highly fragmented table that has never had an index rebuild. Does this table have a Primary Key and/or Clustered Index (usually the same one), if so it has an index. If not, then why not. When you copied the data it was copied with all the data compacted and only taking the space necessary to house it. The first table appears to have been subjected to extensive page splitting..
You need to periodically reindex your tables and update stats. The optimization jobs will help with parts of that. 8GB is big but not that big for a table..
CEWII
June 11, 2012 at 11:56 am
I'm having the same problem on a table with a varbinary(max) column. I have 21 rows at 2 MB in the varbinary(max) column totaling about 44 MB for the table but sp_spaceused shows 310 MB used. Even update statistics or reindexing doesn't change that number. If I copy the data to a new table, it will show 44 MB for the new table. In other words, I don't think reindexing is moving the off page data nor calculating its true size.
June 14, 2012 at 1:29 am
Is it possible the table had a column dropped? Or an update to a previously wide column that made it smaller?
You can duplicate the problem this way:
USE tempdb
GO
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'SizeCheck') DROP TABLE SizeCheck
GO
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'SizeCheck2') DROP TABLE SizeCheck2
GO
CREATE TABLE SizeCheck (
ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
Value VARCHAR(8000)
)
INSERT SizeCheck (Value)
SELECT SPACE(8000)
FROM sys.all_objects
UPDATE SizeCheck SET Value = SPACE(1)
SELECT * INTO SizeCheck2 FROM SizeCheck
EXEC sp_spaceused SizeCheck
EXEC sp_spaceused SizeCheck2
/*
name rows reserved data index size unused
SizeCheck1987 16008 KB15896 KB72 KB40 KB
SizeCheck21987 80 KB 48 KB 8 KB24 KB
*/
June 14, 2012 at 1:09 pm
You got it right! I have a varbinary(max) that holds 25MB and gets updated down to 2MB but even reindexing the clustered index does not recover the space of off page data. Every row wastes 23MB of unused space that is treated as not available. I'm using ss2005.
Viewing 5 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply