Sql-server – Move data from one table to other in batch’s

bulkcopyinsertsql-server-2005

I have a table 18 Million records I need to add append it to another table (with the same structure) I tried the import-export wizard, the problem is that the log gets very very big and eventually it took down the full server, I had to kill the process in middle.

I think if I'll do it in batches it'll be faster, but I don't know how to do it.

(I don't need the old table, a record that has been copied could be deleted)

EDIT: bulk insert block all operations, is there a way to prevent him from blocking everyone here?
enter image description here

Best Answer

while (1=1)
begin
    delete top(10000) from oldtable
       output deleted.columnA, deleted.columnB, deleted.columnC
       into newtable (columnA, columnB, columnC)
    if @@ROW_COUNT = 0
       break;
end