Deleting data in a table

  • Hi Every one,

    I had a requirement to remove all the data in all tables in a database AFTER A CERTAIN PERIOD OF TIME (1 Year). what is the best way of doing this.

    WHETHER I HAVE TO CREATE A JOB OR USE STORED PROCEDURES OR TRIGGERS ...

    Thank you.

  • Two approaches :

    1) partitioning

    2 ) batch process to delete the data (done by scheduled job)

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • does this do the job.

    CREATE PROCEDURE sp_EmplyAllTable

    AS

    EXEC sp_MSForEachTable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’

    EXEC sp_MSForEachTable ‘DELETE FROM ?’

    EXEC sp_MSForEachTable ‘ALTER TABLE ? CHECK CONSTRAINT ALL’

    GO

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

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