Jer*_*oen 4 sql-server-2008 sql-server disk-space
After cleaning my table with 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 KB
Run Code Online (Sandbox Code Playgroud)
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 does not reclaim space, it deletes rows.
Space can remain allocated for several reasons, 3 of which are:
Try
EXEC sp_spaceused 'MyTable', 'true' to force a space used updateTRUNCATE TABLE which deallocates space, rather then deleting rowsDELETE myTABLE WITH (TABLOCKX) 如果没有聚集索引并且不能使用 TRUNCATE不要运行,DBCC shrinkdatabase因为它没有增加任何价值,它只会再次增长