CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Location
    los angeles
    Posts
    1

    Smile delete record after a given time

    Sorry for the newbe question but I can't seem to find the answer in any of the 8 t-sql books I bought.

    I'm running ms sql 2000. I have a table called cart. Some of the items in the cart need to expire after a given amount of time. One of the fields is a datatime field called added. What i need to do is delete the record after 10 minutes.

    I'm tring to user the job wizard to add a job that will run every 30 seconds. If the job finds an item in the cart that is older than 10 minutes it will delete it.

    My imaginary query:

    "Delete from cart where the difference between added and NOW is greater than 10 minutes"

    I can do this programatically on the webserver end but it seems more logical and robust to do it using the sql server.

    Any help would be greatly apreciated.

  2. #2
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309
    The query would look something like this.

    DELETE cart where added < DATEADD(mi,-10,GETDATE())

    However, if this system has a high number of transactions and a good number of indexes you may find it better to set your apps queries up to ignore items over 10 minutes and do a mass delete at an offpeak time instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured