TSQL for automatic Deletion using SQL Job

  • Hi

    I want to create an SQL JOB of type TSQL.

    I have a database field in a table which stores and integer value that is the thresh hold for deleting record. In Another table I have records which are saved with the date on which they are created. Upon reaching a specific date (adding that thresh hold with the date of record created) and a certain boolean value in that record, I want that record to be automatically deleted.

    In other words I want to delete some expired records using a SQL JOB. The job has to be run every day.

    Can anyone help me with how I should proceed.

    Regards

    Yasser

  • In your SSMS go to SQL Server agent / Jobs / Right-mouse click -> New job. In the New Job window put some meaningful name for the job.

    Go to Steps in the left window pane. Click New, New Job step will be displayed. Put step1 or anything in Step name, leave Transact-SQL in Type, put sa in Run As, choose your database from drop-down list.

    In command window, put

    delete your_table

    where your_column > value

    Click Parse to check for errors. If you want the job to be able to report log to you, go to advanced and choose appropriate settings. Click OK.

    Choose Schedules from the left panel of New Job. Click New. Put something like daily sweep in the Name. In Occurs put Daily, put the time in Occurs once at. Click OK, OK.

     

     

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

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