title: Deleting rows in a table a chunk at a time
body: <p>I have a single-column table <code>Ids</code>, which whose column ID is of type <code>uniqueidentifier</code>. I have another table <code>MyTable</code> which has an ID column as well as many other columns. I would like to delete rows from <code>MyTable</code> 1000 at a time, where the ID from <code>MyTable</code> matches an ID in <code>Ids</code>.</p>
  
  <pre><code>WHILE 1 = 1 BEGIN
      DELETE t FROM (SELECT TOP 1000 ID FROM Ids) d INNER JOIN MyTable t ON d.ID = t.ID;
      IF @@ROWCOUNT &lt; 1 BREAK;
      WAITFOR DELAY @sleeptime; -- some time to be determined later
  END
  </code></pre>
  
  <p>This doesn't seem to work though. What should the statement actually be?</p>