Showing posts with label millions. Show all posts
Showing posts with label millions. Show all posts

Monday, March 12, 2012

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

MastinoMassimo (mastino@.hotmail.it) writes:

Quote:

Originally Posted by

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...edViews.01.aspx
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||First, thank you for the answer, Erland, it's not the first time you help me
!

Quote:

Originally Posted by

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.

Quote:

Originally Posted by

>
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...edViews.01.aspx


I do not want, and I cannot use partitioned wiews, I have to delete what we
do not need any more.

Quote:

Originally Posted by

>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx


Thank you

Massimo / Mastino|||Mastino (mastino@.hotmail.it) writes:

Quote:

Originally Posted by

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, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||I will evaluate this way too, but we have to work with millions records
tables.
Thanx

"Erland Sommarskog" <esquel@.sommarskog.seha scritto nel messaggio
news:Xns98E5ED0FE4612Yazorman@.127.0.0.1...

Quote:

Originally Posted by

Mastino (mastino@.hotmail.it) writes:

Quote:

Originally Posted by

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,

Quote:

Originally Posted by

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, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||On Feb 28, 12:20 am, "Massimo" <mast...@.hotmail.itwrote:

Quote:

Originally Posted by

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.

Friday, March 9, 2012

Migration SQL server 2000 to 2005, with heavy use of DTS

We have a big migration from SQL server 2000 to 2005
It is a big procedure aith millions of records and it uses DTSs
heavily, so I am asking some hints on s your experience on
1. "basic" migration of DB ib itself
2. DTS: we read that the Dynamic Properties used by DTS are NOT fully
supported and that would be a great problem for us
Any reporting of other known issues - small, medium or big -
will be greatly appreciated.
Thank you so muchSeveral things to do, the ones I remember:
1) Check BOL section 'Upgrading to SQL Server 2005', 'Backward
Compatibility'. Look for deprecated and discontinued features, breaking
changes and behavior changes.
2) Use the SQL Server Upgrade Advisor and follow its recommendations
3) You may want to consider moving the DTS packages without converting to
SSIS. Check also 'Upgrading to SQL Server 2005', 'Backward Compatibility' fo
r
DTS.
4) Test everything.
Hope this helps,
Ben Nevarez
Senior Database Administrator
AIG SunAmerica
"baruffa66@.gmail.com" wrote:

> We have a big migration from SQL server 2000 to 2005
> It is a big procedure aith millions of records and it uses DTSs
> heavily, so I am asking some hints on s your experience on
> 1. "basic" migration of DB ib itself
> 2. DTS: we read that the Dynamic Properties used by DTS are NOT fully
> supported and that would be a great problem for us
> Any reporting of other known issues - small, medium or big -
> will be greatly appreciated.
> Thank you so much
>|||Hi,
First, if you have not yet done so, get the "Microsoft SQL Server 2005
Upgrade Advisor". You can run this against your SQL Server 2000 server and
it will produce a report on problem areas that you may need to fix. We did
not have much problem, but the old style outer joins (*=, =*) are
deprecated. Also, if you have code that uses system tables some of those
have changed or vanished.
Passwords on 2005 are case-sensitive. This will cause you some problems if
you have code registered to login with a password in a different case from
that stored on the server. (SQL Server 2000 would forgive that, 2005 will
not.)
Since you are DTS heavy, there are "Microsoft SQL Server 2005 Backward
Compatibility Components" and the "Microsoft SQL Server 2000 DTS Designer
Components" to run on SQL Server 2005. Of course, it is the course of
wisdom to upgrade your packages to SSIS prior to SQL Server 2008, but this
can get you into SQL Server 2005 faster, and let you catch up on your DTS
packages one at a time, rather than all at once.
http://technet.microsoft.com/en-us/...aspx#designtime
These additional packages can be found at Feature Pack for Microsoft SQL
Server 2005 - February 2007
a42ec403d17&displaylang=en" target="_blank">http://www.microsoft.com/downloads/...&displaylang=en
RLF
<baruffa66@.gmail.com> wrote in message
news:b48d3fdf-2700-4855-b220-7bd616f33e40@.n20g2000hsh.googlegroups.com...
> We have a big migration from SQL server 2000 to 2005
> It is a big procedure aith millions of records and it uses DTSs
> heavily, so I am asking some hints on s your experience on
> 1. "basic" migration of DB ib itself
> 2. DTS: we read that the Dynamic Properties used by DTS are NOT fully
> supported and that would be a great problem for us
> Any reporting of other known issues - small, medium or big -
> will be greatly appreciated.
> Thank you so much|||Ben and Russel,
thanks a lot.
We asked 5 professionals,
4 of them have not even indirect experience on this migration,
the fifth says that he didn't migrate but is using a module of 2005
that allows to keep those oldies but goodies DTS
and launch them from 2005, without migrating to the new SSIS.
Ciao

Migration SQL server 2000 to 2005, with heavy use of DTS

We have a big migration from SQL server 2000 to 2005
It is a big procedure aith millions of records and it uses DTSs
heavily, so I am asking some hints on s your experience on
1. "basic" migration of DB ib itself
2. DTS: we read that the Dynamic Properties used by DTS are NOT fully
supported and that would be a great problem for us
Any reporting of other known issues - small, medium or big -
will be greatly appreciated.
Thank you so muchSeveral things to do, the ones I remember:
1) Check BOL section 'Upgrading to SQL Server 2005', 'Backward
Compatibility'. Look for deprecated and discontinued features, breaking
changes and behavior changes.
2) Use the SQL Server Upgrade Advisor and follow its recommendations
3) You may want to consider moving the DTS packages without converting to
SSIS. Check also 'Upgrading to SQL Server 2005', 'Backward Compatibility' for
DTS.
4) Test everything.
Hope this helps,
Ben Nevarez
Senior Database Administrator
AIG SunAmerica
"baruffa66@.gmail.com" wrote:
> We have a big migration from SQL server 2000 to 2005
> It is a big procedure aith millions of records and it uses DTSs
> heavily, so I am asking some hints on s your experience on
> 1. "basic" migration of DB ib itself
> 2. DTS: we read that the Dynamic Properties used by DTS are NOT fully
> supported and that would be a great problem for us
> Any reporting of other known issues - small, medium or big -
> will be greatly appreciated.
> Thank you so much
>|||Hi,
First, if you have not yet done so, get the "Microsoft SQL Server 2005
Upgrade Advisor". You can run this against your SQL Server 2000 server and
it will produce a report on problem areas that you may need to fix. We did
not have much problem, but the old style outer joins (*=, =*) are
deprecated. Also, if you have code that uses system tables some of those
have changed or vanished.
Passwords on 2005 are case-sensitive. This will cause you some problems if
you have code registered to login with a password in a different case from
that stored on the server. (SQL Server 2000 would forgive that, 2005 will
not.)
Since you are DTS heavy, there are "Microsoft SQL Server 2005 Backward
Compatibility Components" and the "Microsoft SQL Server 2000 DTS Designer
Components" to run on SQL Server 2005. Of course, it is the course of
wisdom to upgrade your packages to SSIS prior to SQL Server 2008, but this
can get you into SQL Server 2005 faster, and let you catch up on your DTS
packages one at a time, rather than all at once.
http://technet.microsoft.com/en-us/library/ms143706.aspx#designtime
These additional packages can be found at Feature Pack for Microsoft SQL
Server 2005 - February 2007
http://www.microsoft.com/downloads/details.aspx?FamilyID=50b97994-8453-4998-8226-fa42ec403d17&displaylang=en
RLF
<baruffa66@.gmail.com> wrote in message
news:b48d3fdf-2700-4855-b220-7bd616f33e40@.n20g2000hsh.googlegroups.com...
> We have a big migration from SQL server 2000 to 2005
> It is a big procedure aith millions of records and it uses DTSs
> heavily, so I am asking some hints on s your experience on
> 1. "basic" migration of DB ib itself
> 2. DTS: we read that the Dynamic Properties used by DTS are NOT fully
> supported and that would be a great problem for us
> Any reporting of other known issues - small, medium or big -
> will be greatly appreciated.
> Thank you so much|||Ben and Russel,
thanks a lot.
We asked 5 professionals,
4 of them have not even indirect experience on this migration,
the fifth says that he didn't migrate but is using a module of 2005
that allows to keep those oldies but goodies DTS
and launch them from 2005, without migrating to the new SSIS.
Ciao

Wednesday, March 7, 2012

Migration Millions of Records

Hi

Please guide me for the below given problem.

While doing migration by using cursors for the below given sample data its taking more hours to complete the process. Therefore want to know is there any way I can do it in simple query.

ACNo Amount Balance CalType
A001 10 10 +
A001 10 20 -
A001 40 40 +
A001 10 30 -
A002 90 90 +
A002 20 110 +
A002 40 150 +
A003 10 30 +
A003 10 40 +
A003 10 30 -
A004 40 40 +
A004 10 30 -

Iam having Amount value alone and Balance has to be calculated value based on CalType. At the same time the Balance has to be reset as 0 when AcNo has changed.

Please guide me for the faster approach.

Regards,
Mohanraj

It is not clear what you want help with.

Your data does not appear to be consistant. (It appears that the second row for [A001] should have a Balance of [0], and it appears that the first two rows of [A003] have incorrect Balance amounts.

Also, there is no column that can be used to determine sequencing, i.e., a datetime column or a IDENTITY field.

Do you wish ONLY a summary row with the correct Balance?

OR

Do you wish to 're-calculate' the Balance Column?

This can be very efficiently accomplished without using a CURSOR, #Temp tables, or table variables. It is really just a SET based operation.

|||

The data doesn't seem right.&nbsp; That said:&nbsp; there are ways to calculate running balances without using a cursor, but the methods (using COALESCE or cross-joins) are actually slower than using a cursor.&nbsp; (See <a href="http://www.sqlteam.com/article/calculating-running-totals">this article by Garth Wells</a> for a discussion of the various methods.)

What you don't want to do, though, is use a cursor to update your production table. Create a table variable to hold the running balances. Use a read-only cursor to read through your production table and populate the table variable. Then update the production table with the table variable when you're done.

|||

Hi Arnie,

Thanks for your reply.

ACNo Amount Balance CalType Ident_Column
A001 10 10 + 1
A001 10 20 - 2
A001 40 40 + 3
A001 10 30 - 4
A002 90 90 + 5
A002 20 110 + 6
A002 40 150 + 7
A003 30 30 + 8
A003 10 40 + 9
A003 10 30 - 10
A004 40 40 + 11
A004 10 30 - 12

Yeah, you are correct earlier data was wrongly posted, now it has highlighed as yellow in color.

Now I have added Identity column.

When AccountNumber has changed the balance need to recalculate.

Please provide me some faster approach.

Regards,

Mohanraj