Is there any solution for bulk delete in SQL Server?
I can't use TRUNCATE because I want to use WHERE for limiting the rows in action.
Is there anything like Bulk Copy (bcp) for delete data?
BCP is faster in most cases then BULK Insert.
In case you want to empty the table, it is advisable to use the truncate statement. The truncate statement removes all of the data from a table, uses minimal transaction logging, resets the identity value range, and is faster than the SQL delete statement because it deallocates all the pages for the table immediately.
No.
You want a DELETE with a WHERE clause: this is standard SQL.
What you can do is batch deletes like this:
SELECT 'Starting' --sets @@ROWCOUNT
WHILE @@ROWCOUNT <> 0
DELETE TOP (xxx) MyTable WHERE ...
Or if you want to remove a very high percentage of rows...
SELECT col1, col2, ... INTO #Holdingtable
FROM MyTable WHERE ..opposite condition..
TRUNCATE TABLE MyTable
INSERT MyTable (col1, col2, ...)
SELECT col1, col2, ... FROM #Holdingtable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With