SQL : Bulk Delete in Batches

SQL : Bulk Delete in Batches

The following query will delete rows from a table in batches of 200, this can help reduce locks during the delete process on tables with a large row count. You can increase the rowcount by changing the number in red;

SET ROWCOUNT 200
WHILE 1 = 1
BEGIN
  DELETE FROM messages

  IF @@ROWCOUNT = 0
  BREAK
END