patternsqlMinor
SQL-Server: sp_spaceused gives zero rows but big dataSize for cleaned table
Viewed 0 times
rowssp_spaceusedsqldatasizebutcleanedbiggivesforserver
Problem
After cleaning my table with
As you can see there are zero rows, yet there's almost 21 MB of data. My question is: what are possible causes for this situation and/or how can I further investigate this?
DELETE FROM MyTable (and executing DBCC shrinkdatabase('MyDB') should that matter) I run the statement EXEC sp_spaceused MyTable. The results confuse me:tableName numberOfRows reservedSize dataSize indexSize unusedSize
--------- ------------ ------------ -------- --------- ----------
MyTable 0 21664 KB 20672 KB 736 KB 256 KBAs you can see there are zero rows, yet there's almost 21 MB of data. My question is: what are possible causes for this situation and/or how can I further investigate this?
Solution
DELETE does not reclaim space, it deletes rows.
Space can remain allocated for several reasons, 3 of which are:
Try
Don't run
Space can remain allocated for several reasons, 3 of which are:
- ghost clean up is still running
- the table has no clustered index
- the system tables are not updated yet
Try
EXEC sp_spaceused 'MyTable', 'true'to force a space used update
TRUNCATE TABLEwhich deallocates space, rather then deleting rows
DELETE myTABLE WITH (TABLOCKX)if no clustered index and can't use TRUNCATE
Don't run
DBCC shrinkdatabase because it adds no value and it will simply grow againContext
StackExchange Database Administrators Q#9141, answer score: 5
Revisions (0)
No revisions yet.