I have written some code in C# that deletes records from a database. It's your straightforward SQL delete code enclosed in a transaction.
using (SqlTransaction trans = conn.BeginTransaction()) {
//some delete code
trans.Commit();
}
I have deleted about 4 million rows across 4 tables in my database. When I checked the database backup size of both DBs via Windows Explorer, the size has dramatically increased about thrice
- Before deletion: 7GB
- After deletion: 28GB
I confirmed that both the MDF and the LDF files increased in size. I also noticed that some tables that are not affected by the delete have their index size increased.
After deletion:
Before deletion:
My goal is to delete records to reduce the database size but it increased instead. Can you tell me why the size is increasing?
EDIT:
After deletion:
- database_size: 61050.69 MB
- unallocated space: 9592.60 MB
- reserved: 303512 KB
- data: 207040 KB
- index_size: 53024 KB
- unused: 43448 KB
Before deletion:
- database_size: 10067.88 MB
- unallocated space: 16.69 MB
- reserved: 7290176 KB
- data: 2937656 KB
- index_size: 4324848 KB
- unused: 27672 KB