Delete data from table in chunks without getting out of disk space due to transaction log

Today I found myself trying to delete million of rows from a table with over 200.000.000 rows. A simple Delete From tbData Where ID < 100000000 resulted in a full disk space and a huge transaction log file. The solution came from this post:

deleteMore:
Delete TOP(10000) tbData Where CDRID < 100000000
IF @@ROWCOUNT != 0
    goto deleteMore;

The TOP(10000) is up to you and you should adjust it to your data. For me the optimal value was 500000.

Comments

Popular posts from this blog

Freeze panes in BO Webi report like Excel

IIS "Access to the path 'C:\inetpub\wwwroot...' is denied."

ASP.NET entity datasource control error - The metadata specified in the connection string could not be loaded. Consider rebuilding the web project to build assemblies that may contain metadata.The following error(s) occurred. The provider did not return a Provider Manifest instance.