SQL-Server: sp_spaceused gives zero rows but big dataSize for cleaned table

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?

gbn*_*gbn 5

DELETE does not reclaim space, it deletes rows.

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 TABLE which deallocates space, rather then deleting rows
  • DELETE myTABLE WITH (TABLOCKX) 如果没有聚集索引并且不能使用 TRUNCATE

不要运行,DBCC shrinkdatabase因为它没有增加任何价值,它只会再次增长