Chapter 30. Reusing space in a table
People who have switched to Microsoft SQL Server from Microsoft Access sometimes ask, “If I delete a bunch of rows, do I need to compact my SQL Server database?”
It’s been many years since I’ve used Access, but I still remember the reason for their concern. Access would continually add rows to the end of the table. If some, or even all, of the rows were deleted from the table, Access wouldn’t reuse the space. It kept adding rows to the end of the table and never backfilled the holes. Compacting the Access database file would get rid of the holes.
I’m not an expert in Access, and I’m certainly not knocking it. I haven’t even used Access since v2.0 back in the 1990s. This behavior may have changed since then, or perhaps I misremember, but suffice it to say that with SQL Server this is not an issue. But don’t take my word for it. Let’s consider an example to prove the point.
To set up the example, let’s create a table with three columns and then populate it with test data. The T-SQL code for doing this is shown in listing 1.