SQL Server Performance

Delete rows from a table

Discussion in 'Getting Started' started by klehonia, Sep 14, 2009.

  1. klehonia New Member

    Hi everyone, i want a query that delete rows from a table that are older than 3 days. There is a column with the datetime.
    Thanks in advance
  2. FrankKalis Moderator

    DELETE MyTable WHERE DateTimeColumn < DATEADD(DAY, -3, GETDATE())
    Note that because of the time portion involved here, the statement does not delete rows from 3 days ago where the time was later than the current time. If that is not what you want you would have to strip out the time portion in GETDATE().
  3. klehonia New Member

    Thank you very much. It works fine.

Share This Page