473,507 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

millions records archiving and delete

The iussue:

Sql 2K
I have to keep in the database the data from the last 3 months.
Every day I have to load 2 millions records in the database.
So every day I have to export (in an other database as historical data
container) and delete the 2 millions records inserted 3 month + one day ago.

The main problem is that delete operation take a while...involving
transaction log.

The question are:
1) How can I improve this operation (export/delete)
2) If we decide to migrate to SQL 2005, may we use some feature, as
"partitioning" to resolve the problems ? In oracle I can use the "truncate
partition" statement, but in sql 2005, I'm reading, it cant be done.
This becouse we can think to create a partition on the last three mounts to
split data. The partitioning function can be dinamic or containing a
function that says "last 3 months ?" I dont think so.

May you help us
thank you

Mastino

Feb 27 '07 #1
5 6694
Massimo (ma*****@hotmail.it) writes:
Sql 2K
I have to keep in the database the data from the last 3 months.
Every day I have to load 2 millions records in the database. So every
day I have to export (in an other database as historical data container)
and delete the 2 millions records inserted 3 month + one day ago.

The main problem is that delete operation take a while...involving
transaction log.

The question are:
1) How can I improve this operation (export/delete)
2) If we decide to migrate to SQL 2005, may we use some feature, as
"partitioning" to resolve the problems ? In oracle I can use the
"truncate partition" statement, but in sql 2005, I'm reading, it cant be
done. This becouse we can think to create a partition on the last three
mounts to split data. The partitioning function can be dinamic or
containing a function that says "last 3 months ?" I dont think so.
Permit me to start with SQL 2005. There you have partitioned tables,
and in a case like yours you would set up the table with let's say
four partitions, with the month as the partitioning column. To delete
old rows, you would simply take that table out of the partition
table, and then drop table that table. You in the same manner, shift
in a new table for the next month. Here I said month, but you have one
partition per day, and have 90 partitions if you like - whether this
is a good idea I don't know.

Note that partitioned tables are only available in the Enterprise
(and Developer) Edition of SQL 2005.

In SQL 2005, you would use partitioned views (and here 90 paritions
would definitely go beyond what is manageable). One table per month
and then they are united in a view with a UNION ALL statement. At
a new month you would run a job that dropped the table from four
months back, and create a new table. Notice that you can load directly
to the new, and data should turn in the right place.

See also Stefan Delmarco's article on partitioned views:
http://www.fotia.co.uk/fotia/FA.02.S...dViews.01.aspx
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 27 '07 #2
First, thank you for the answer, Erland, it's not the first time you help me
!
Permit me to start with SQL 2005. There you have partitioned tables,
and in a case like yours you would set up the table with let's say
four partitions, with the month as the partitioning column. To delete
old rows, you would simply take that table out of the partition
table, and then drop table that table. You in the same manner, shift
in a new table for the next month. Here I said month, but you have one
partition per day, and have 90 partitions if you like - whether this
is a good idea I don't know.
Reading and reading over the internet, I found that I can transfer the data
to be dropped with a:

ALTER TABLE SWITCH...

and I can also make partition function dynamic:

http://msdn2.microsoft.com/en-us/library/aa964122.aspx

now I'm studying hard for the solution, the problems to resolve are many.

>
Note that partitioned tables are only available in the Enterprise
(and Developer) Edition of SQL 2005.

In SQL 2005, you would use partitioned views (and here 90 paritions
would definitely go beyond what is manageable). One table per month
and then they are united in a view with a UNION ALL statement. At
a new month you would run a job that dropped the table from four
months back, and create a new table. Notice that you can load directly
to the new, and data should turn in the right place.

See also Stefan Delmarco's article on partitioned views:
http://www.fotia.co.uk/fotia/FA.02.S...dViews.01.aspx
I do not want, and I cannot use partitioned wiews, I have to delete what we
do not need any more.
>

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Thank you

Massimo / Mastino

Feb 28 '07 #3
Mastino (ma*****@hotmail.it) writes:
I do not want, and I cannot use partitioned wiews, I have to delete what
we do not need any more.
Why would partitioned views prevent that? When it's time to delete old data,
you first redefine the view, so that the tables to be dropped are not
in the view any more. Then deleting is just dropping the table.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 28 '07 #4
I will evaluate this way too, but we have to work with millions records
tables.
Thanx

"Erland Sommarskog" <es****@sommarskog.seha scritto nel messaggio
news:Xn**********************@127.0.0.1...
Mastino (ma*****@hotmail.it) writes:
I do not want, and I cannot use partitioned wiews, I have to delete what
we do not need any more.

Why would partitioned views prevent that? When it's time to delete old
data,
you first redefine the view, so that the tables to be dropped are not
in the view any more. Then deleting is just dropping the table.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Feb 28 '07 #5
On Feb 28, 12:20 am, "Massimo" <mast...@hotmail.itwrote:
The iussue:

Sql 2K
I have to keep in the database the data from the last 3 months.
Every day I have to load 2 millions records in the database.
So every day I have to export (in an other database as historical data
container) and delete the 2 millions records inserted 3 month + one day ago.

The main problem is that delete operation take a while...involving
transaction log.

The question are:
1) How can I improve this operation (export/delete)
2) If we decide to migrate to SQL 2005, may we use some feature, as
"partitioning" to resolve the problems ? In oracle I can use the "truncate
partition" statement, but in sql 2005, I'm reading, it cant be done.
This becouse we can think to create a partition on the last three mounts to
split data. The partitioning function can be dinamic or containing a
function that says "last 3 months ?" I dont think so.

May you help us
thank you

Mastino
Just out of curiosity, do you have to log the delete operation? You
can truncate the tables but that is not logged.

Mar 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3472
by: Benoit St-Jean | last post by:
I am looking at options/ways to store 12 million gif/jpg images in a database. Either we store a link to the file or we store the image itself in the database. Images will range from 4k to 35k in...
2
5411
by: Mathieu Pagé | last post by:
Hi, I already found on the MySQL web site that some users did have good results with tables of some millions records. But, what I want to do is store some hundreds millions records in a...
3
2212
by: Steve | last post by:
I have a query that returns raw tick data from a table. Unfortunately after even a few days there are hundreds of thousands of rows so the following query is not efficient. SELECT * FROM...
19
6744
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
1
4796
by: Sally Ruggero | last post by:
I need advice on archiving data from our production database. Each night I would like to save and remove a day's data from two weeks ago, from all the tables. I know how to delete the...
3
2688
by: rperetz | last post by:
Hi all, I was given a task to create a houseHolding logic under a table that have millions records. first let me explain what is a house holding: let's say I have 2 records that have the same...
8
2641
by: powelly | last post by:
I have a Delete button with this code atached Private Sub Delete_Click() On Error GoTo Err_DoArchive Dim ws As DAO.Workspace Dim db As DAO.Database Dim bInTrans As Boolean Dim...
1
2832
by: dmcadams | last post by:
I need help deleting 300 Millions of rows from a table and then reclaim the space in the table after completing the delete process. The database needs to be online and available to the users. There...
1
2407
by: Shortstuff12345 | last post by:
This can be ignored... I did a bunch more searching and tried a few more things listed on different posts. I was able to get the delete query to work properly by adding a statement in the code...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.