SQL Server Performance

truncating data older than 30 days

Discussion in 'Getting Started' started by SQL DBA, Dec 14, 2007.

  1. SQL DBA New Member

    Hi,
    I have a table with
    C1- ID
    C2-Date
    C3-Date with time
    C4-quantity
    I need to create a daily process that will remove the oldest data(data older than 30 days) on the table and make sure the table is with only 30 days worth of data.
    Please help me.
    Thanks in advance
  2. ndinakar Member

    DELETE Table WHERE C3 < Datediff(dd, 30, Getdate())
  3. ndinakar Member

    You can set up a job that runs every night and cleans up the data.
  4. ranjitjain New Member

    If you have stored insertdate in c3 column then the query should be
    delete yourtable where c3<dateadd(dd,-30,getdate())
    This query will check recordsdate which are less than 30 days old and will delete it. Also as suggested put this query as a agent job and schedule it to run midnight.

Share This Page