January 30, 2015 at 4:49 am
A lot of unwanted rows got entered into a table due to a faulty script. This caused the database to grow by 6GB. I need to delete these rows. The table has a unique non-clustered index only, no keys. I tried deleting the rows in chunks.
After deleting about a million rows, I noticed that though the row count has decreased, the table size is growing. I am confused. I stopped deleting the rows till I can figure out why the table size is not decreasing. Can someone please explain to me what is going on. Thanks.
January 30, 2015 at 5:14 am
vsuresh (1/30/2015)
A lot of unwanted rows got entered into a table due to a faulty script. This caused the database to grow by 6GB. I need to delete these rows. The table has a unique non-clustered index only, no keys. I tried deleting the rows in chunks.After deleting about a million rows, I noticed that though the row count has decreased, the table size is growing. I am confused. I stopped deleting the rows till I can figure out why the table size is not decreasing. Can someone please explain to me what is going on. Thanks.
If you are saying the table is a heap, i.e. no clustered index, then you are observing expected behaviour:
http://sqlmag.com/blog/curious-case-empty-heap-table
https://technet.microsoft.com/en-us/library/ms189245(v=sql.105).aspx
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 30, 2015 at 7:02 am
Thank you for replying. Do you know why the table size would increase though? If the pages are not getting deallocated because it is a heap, at least wouldn't it remain the same. I would just like to understand better, hence the question. Thanks again.
January 30, 2015 at 11:12 am
Aren't people also adding rows at the same time?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 30, 2015 at 11:32 am
I did this during off hours when no one else is accessing that table, hence I'm puzzled.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply