Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


data archiving


data archiving

Author
Message
blnbmv
blnbmv
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 114
Hi members,

I have some tables in my database and in each table every month fresh data gets added to the previous data. The approximate size of the data that get added to the tables is 1.5 - 2 million records and my Project Manager wants to archive the data. She wants only 6 months of data in main table and rest of the data should be archived to respective archive tables.

Can anyone explain me how to archive the data in a table and what are the methods in archiving the data. Please suggest me along within an example and also explain me how to access that data which is archived later point of time when all my procedures initially referring to the main table.

Thanks in advance

sai
homebrew01
homebrew01
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2976 Visits: 9071
This sounds a bit like a generic homework assignment ..... so here's a generic answer

1) Copy records older than 6 months into archive tables.

insert into Archive_table select * from Prod_table
where Archive_date < DATEADD(MONTH, -6, (getdate()))

2) Delete records older than 6 months from production tables.

delete from Prod_table
where Archive_date < DATEADD(MONTH, -6, (getdate()))

3) Change your stored procedures to point to the archive tables.



PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3093 Visits: 4639
You may want to research table partitioning.
Table partitioning allows for the fastest and cleanest way to achive data archiving and purging.

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44948 Visits: 39860
Sai,

Once you get the intial archive done, how many rows would need to be archived on a daily basis? Also, please post the CREATE TABLE statement for the table involved as well as what the indexes are... you'll get a much better answer. Wink

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
     Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
gan-685682
gan-685682
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 215
PaulB (8/24/2008)
You may want to research table partitioning.
Table partitioning allows for the fastest and cleanest way to achive data archiving and purging.


Sorry, I am curious how the table partitioning affect the database, if the database is running 24/7. I found all the example in MSDN is cold archiving, I once tried to use the hot archiving (dynamic queries for table partitioning to let it running weekly/bi-weekly/monthly) but the table still get locked, thought the partition switching is pretty fast.
rajankjohn
rajankjohn
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1201 Visits: 575
You can go for the sliding window partitioning. See the whitepaper by Kimberly Tripp on this - http://msdn.microsoft.com/en-us/library/ms345146(SQL.90).aspx
gan-685682
gan-685682
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 215
Yes, I have gone thru' that. That's what I meant cold archiving (predefined values). I have tried to do something like this:

SET @SQLString = N'ALTER PARTITION SCHEME [' + @archiveScheme + '] NEXT USED [FileGroup_MDPTSP]'
...
SET @SQLString = N'ALTER PARTITION FUNCTION ' + @archiveFunction + '()
                                 SPLIT RANGE ('''
                  SET @strTEMP = CONVERT(NCHAR(8), DATEADD(day, 7, @dtStart), 112) -- +7 next partition
                  SET @SQLString = @SQLString + @strTEMP + ''')'
..
SET @SQLString = N'ALTER TABLE ' + @factTable + ' Switch Partition 1
                                    TO ' + @archiveTable + ' Partition 2 '
...
SET @SQLString = N'ALTER PARTITION FUNCTION ' + @factFunction + '()
                                 SPLIT RANGE ('''
                  SET @strTEMP = CONVERT(NCHAR(8), DATEADD(day, (7 + 1) , @dtEnd), 112) -- +1 bcoz of this is executre 2nd last day
                  SET @SQLString = @SQLString + @strTEMP + ''')'



in order let it work dynamically. Is that way right?
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44948 Visits: 39860
If the clustered key is set by date or, perhaps, identity and the identity column is indicative of entry order, then sectional deletes (or insert to archive, delete from source) of, say, 20,000 rows at a time will work just fine.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
     Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
gan-685682
gan-685682
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 215
Jeff Moden (8/25/2008)
If the clustered key is set by date or, perhaps, identity and the identity column is indicative of entry order, then sectional deletes (or insert to archive, delete from source) of, say, 20,000 rows at a time will work just fine.

Hi Jeff, are you answered to my question? 20,000 rows ? what about 200, 000 or even 2,000,000 rows?
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44948 Visits: 39860
gan (8/26/2008)
Jeff Moden (8/25/2008)
If the clustered key is set by date or, perhaps, identity and the identity column is indicative of entry order, then sectional deletes (or insert to archive, delete from source) of, say, 20,000 rows at a time will work just fine.

Hi Jeff, are you answered to my question? 20,000 rows ? what about 200, 000 or even 2,000,000 rows?


Yep... answering your question and the OPs question... if the system is a 24/7 operation and the table you want to archive is in use, then trust me and do it 20,000 rows at a time. Or, not... simple delete with very few indexes runs very fast and will probably delete 2 million rows, no problem. Oh, but there's that 24 hour thingy getting in the way and since the table is probably indexed for use and maybe has a clustered index that isn't exactly chronilogical, it could take several hours to delete just 2 million rows. Only way to know for sure is to try it... run the delete for 2 million rows... if it takes more than about 10 minutes, you should probably stop it and rollback. If it takes less than 10 minutes, then problem solved. By the way, there will be some serious blocking on the table during the 2 million row delete... I wouldn't try it on a real busy 24/7 system that has short SLA requirements. Smile

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
     Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search