Use temporary tables, and once the insert is done, rename the existing table, then rename the temporary table to the real table name.