Purging old records in SQL table

  • Hi,

    simple scripts Purging the old records in table.

    I have more than 1Lakh records, can any one tell me simple way to purge this old records.

    i am using below scripts

    delete from table_name where date_created < dateadd(d,-365,GETDATE())

    delete from events where datediff(m,datecolumn,getdate()) >= 365

    DELETE FROM <tableName> WHERE datecolumn < getdate()-365

    Above scripts are taking more time and some times we are not gaining the Space also.

    Please help on this.

  • Hi,

    Try this code may help you

    ALTER TABLE table_name NOCHECK CONSTRAINT ALL

    ALTER TABLE table_name DISABLE TRIGGER ALL

    make your delete

    ALTER TABLE table_name CHECK CONSTRAINT ALL

    ALTER TABLE table_name ENABLE TRIGGER ALL

    Regards

    IgorMi

    Igor Micev,My blog: www.igormicev.com

  • You can start by reading this article: http://www.sqlservercentral.com/articles/T-SQL/67898/.

  • santhosh411 (8/9/2012)


    Hi,

    simple scripts Purging the old records in table.

    I have more than 1Lakh records, can any one tell me simple way to purge this old records.

    i am using below scripts

    delete from table_name where date_created < dateadd(d,-365,GETDATE())

    delete from events where datediff(m,datecolumn,getdate()) >= 365

    DELETE FROM <tableName> WHERE datecolumn < getdate()-365

    Above scripts are taking more time and some times we are not gaining the Space also.

    Please help on this.

    Also, if you are expecting disk space to be released back to the OS by deleting records, not going to happen. The space you reclaim will be in the database.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply