I have a database with large varbinary(MAX) duplicate records in one of my tables in SQL Server 2019. We needed to remove the duplicates so I ran a delete query to remove the duplicates. Instead of the database size remaining the same before the delete statement, it rather increased after the completion of the query. I am about to apply DBCC SHRINKFILE(N'myDatabase', 0), but I am really curious to know why the database size went up. Attached is my Delete query.
DELETE from Document WHERE DocumentId in
(
SELECT t.DocumentId
FROM (
SELECT s.*,
ROW_NUMBER() OVER (PARTITION BY s.DocumentName, s.SubmitDateTime, s.DocumentType ORDER BY s.DocumentName, s.SubmitDateTime, s.DocumentType) AS [RowCount]
FROM Document s
LEFT OUTER JOIN Staging b ON s.DocumentId = b.DocumentId
LEFT OUTER JOIN RejectTable r ON s.DocumentId = r.DocID
WHERE b.DocumentId IS NULL
AND r.DocID IS NULL
AND s.SubmitDateTime IS NOT NULL
AND s.InsertDateTime IS NOT NULL
AND s.DocumentName IS NOT NULL
AND s.DocumentContent IS NOT NULL
AND s.Description ='EmployeesDocument'
) t
WHERE t.[RowCount] > 1
)