locked
How to set auto delete function in SQL Server ? RRS feed

  • Question

  • Hi, May i know is it anyway to set an auto delete function  in SQL server management studio 2008 ? example,set auto delete function in table to delete after one month data record. thank you.  
    Thursday, November 22, 2012 9:28 AM

Answers

All replies

  • You can write the SQL code to delete and schedule(Monthly once) it in job.

    Or you can write your business logic and schedule accordingly in the SQL job


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


    • Edited by ganeshkuppuswamy Thursday, November 22, 2012 9:33 AM
    • Proposed as answer by Naomi N Thursday, November 22, 2012 9:04 PM
    Thursday, November 22, 2012 9:32 AM
  • Use a scheduled job to do this

    http://msdn.microsoft.com/en-us/library/ms190268.aspx


    Many Thanks & Best Regards, Hua Min

    Thursday, November 22, 2012 9:32 AM
  • There is no auto delete function for this.
    You need to create a job and schedule it in the server.

    Best Regards, Venkat

    Thursday, November 22, 2012 9:33 AM
  • Hi, Can you show me an example ? 

    thank you 

    Thursday, November 22, 2012 9:41 AM
  • Hi,

    You can do it by using SQL JOB, you can Set a Time Interval how much you need.

    Check the below link similar to your question.

    http://www.dailycoding.com/Posts/step_by_step_guide_to_add_a_sql_job_in_sql_server_2005.aspx


    PS.Shakeer Hussain

    Thursday, November 22, 2012 9:43 AM
  • Hi, Can you show me an example ? 

    thank you 

    See the below video

    http://www.youtube.com/watch?v=De_GOwnTDjo


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Thursday, November 22, 2012 9:50 AM
  • Please try the steps in the following URL..

    http://www.dailycoding.com/Posts/step_by_step_guide_to_add_a_sql_job_in_sql_server_2005.aspx

    Thanks.


    Best Regards, Venkat

    Thursday, November 22, 2012 9:52 AM
  • >set auto delete function in table to delete after one month data record. thank you. 

    You have to write a delete stored procedure and test it.

    Set up a SQL Server Agent job, the execution of the stored procedure as a job step.

    Set up a schedule for the job.

    Here is an image of the scheduler:


    Kalman Toth SQL 2008 GRAND SLAM
    New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012

    • Marked as answer by Iric Wen Monday, December 3, 2012 6:42 AM
    Thursday, November 22, 2012 1:22 PM
  • As other mention, There is no auto delete function is SQL Server.

    Although, this is a purging requirement of old data.

    You can write your logic & schedule a SQL agent job to perform auto delete on set time on regular intervals. 


    Regards,
    Rohit Garg
    (My Blog)
    This posting is provided with no warranties and confers no rights.
    Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread.

    Thursday, November 22, 2012 4:43 PM
  • Hi

    you may create Agent job describe below details steps:

    http://msdn.microsoft.com/en-us/library/ms181153.aspx 

    Making an application:

    First create a console application with all your clear-data logic. Then add a windows schedule for the .exe file you created. Please see how to schedule a task (article). If you are working with Windows 7. Programmes -> Task Scheduler -> Create a Task (main window right hand side) -> Add a task name -> Actions -> New (bottom) -> Browse your .exe file -> click ok -> Add necessary Trigger information.


    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

    Thursday, November 22, 2012 6:05 PM