Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    5

    Cool Unanswered: Archiving and deleting script

    Hi Guys

    Im using SQL sever 2005. Can someone help me with a script that first archive orders that are 3 years older and then perform a delete that can be rolledback? I need your your assistance please. thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    if you post the DDL of the table(s) and some sample data...perhaps we can help
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    i would say something along the lines of:

    Code:
    Select * from table(s)
    where date <= current date - 3 years
    save the output to a table, then

    Code:
    delete from table(s)
    where date <= current date - 3 years
    If this data is in multiple tables that are referentially related, it gets a bit more complex, as the date is probably in one table. There are third party tools you can purchase that will perform those types of tasks a lot simpler than what you could come up with.
    Dave

Posting Permissions

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