If I populate the following table:
IF OBJECT_ID ('dbo.CleanTableTest', 'U') IS NOT NULL
DROP TABLE dbo.CleanTableTest;
GO
CREATE TABLE dbo.CleanTableTest
(FileName nvarchar(4000),
DocumentSummary nvarchar(max),
Document varbinary(max)
);
GO
-- Populate the table with data from the Production.Document table.
INSERT INTO dbo.CleanTableTest
SELECT REPLICATE(FileName, 1000),
DocumentSummary,
Document
FROM Production.Document;
GO
exec sp_spaceused CleanTableTest
go
Results:
name rows reserved data index_size unused
-------------- ---- --------- ------- ----------- ------
CleanTableTest 13 456 KB 440 KB 8 KB 8 KB
But then if I delete all the rows:
delete dbo.CleanTableTest
go
exec sp_spaceused CleanTableTest
go
Results:
name rows reserved data index_size unused
-------------- ---- -------- ------ ---------- -------
CleanTableTest 0 88 KB 80 KB 8 KB 0 KB
Why after the delete process of all rows in table the unused space have not changed? It stays at 0 KB.
Best Answer
You really need to look at the definition of
sp_spaceused
to find your answer of whyunused
is zero.Take a look at a snippet here of the stored procedure:
That's copied directly from the definition of
sp_spaceused
. Take note of howunused
is actually defined: reserved pages subtracted by used pages (provided reserved pages is greater than used pages, rationally and programmatically).So that is why your
unused
column is what it is. Reverse engineering will explain it all.