title: Remove records by clustered or non-clustered index
body: <p>I have a table (let's say <code>ErrorLog</code>)</p>
  
  <p><a href="https://i.stack.imgur.com/8RJsk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8RJsk.png" alt="enter image description here"></a></p>
  
  <pre><code>CREATE TABLE [dbo].[ErrorLog]
  (
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Created] [datetime] NOT NULL,
      [Message] [varchar](max) NOT NULL,
  
      CONSTRAINT [PK_ErrorLog] 
          PRIMARY KEY CLUSTERED ([Id] ASC)
  )
  </code></pre>
  
  <p>I want to remove all records that are older that 3 months.</p>
  
  <p>I have a non-clustered index on the <code>Created</code> column (ascending).</p>
  
  <p>I am not sure which one of these is better (seem to take same time).</p>
  
  <p><strong>Query #1</strong>:</p>
  
  <pre><code>DELETE FROM ErrorLog
  WHERE Created &lt;= DATEADD(month, - 3, GETDATE())
  </code></pre>
  
  <p><strong>Query #2</strong>:</p>
  
  <pre><code>DECLARE @id INT
  
  SELECT @id = max(l.Id)
  FROM ErrorLog l
  WHERE l.Created &lt;= DATEADD(month, - 3, GETDATE())
  
  DELETE FROM ErrorLog
  WHERE Id &lt;= @id
  </code></pre>