Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Moving large amount of data

 
   Database Help (Home) -> Programming RSS
Next:  Table variable  
Author Message
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 1) Posted: Fri Jan 08, 2010 8:03 am
Post subject: Moving large amount of data
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I have a stored procedure that we've been using here for many months
that allows us to migrate data from a production databse to test and
dev so we always have fresh (and real) data to play with. I couldn't
just backup/restore as I may have added new stored procs or new
columns to the target tables and I don't want these overwritten. The
solution was to create a data-driven stored proc that would iterate
all the tables that the source and target have in common. Then, for
each table, it would iterate all the columns that are in common to
create a dynamic INSERT INTO...SELECT FROM statement that would list
all the common fields.

My question is how to handle very large tables. INSERT INTO...SELECT
FROM works isn't always the best approach when dealing with tables
that have row counts in the tens of millions and greater. These often
take hours to move.

Given what we're trying to do here, Does anyone have a better
suggestion as to how to handle this dynamically?

If anyone would like me to post the stord proc (it works quite well)
I'll be happy to do so.

Thanks

Carl

 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 2) Posted: Fri Jan 08, 2010 8:21 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 8, 11:09 am, "Michael Coles" wrote:
> Meant to add a couple of references:http://msdn.microsoft.com/en-us/library/ms188029.aspxhttp://msdn.microsoft.com/en-us/library/ms191244.aspx
>
> --
> Thanks
>
> Michael Coles
> SQL Server MVP
> Author, "Expert SQL Server 2008 Encryption"
> (http://www.apress.com/book/view/1430224649)
> ----------------
>
> "SetonSoftware" wrote in message
>
>
>
>
>
> >I have a stored procedure that we've been using here for many months
> > that allows us to migrate data from a production databse to test and
> > dev so we always have fresh (and real) data to play with. I couldn't
> > just backup/restore as I may have added new stored procs or new
> > columns to the target tables and I don't want these overwritten. The
> > solution was to create a data-driven stored proc that would iterate
> > all the tables that the source and target have in common. Then, for
> > each table, it would iterate all the columns that are in common to
> > create a dynamic INSERT INTO...SELECT FROM statement that would list
> > all the common fields.
>
> > My question is how to handle very large tables. INSERT INTO...SELECT
> > FROM works isn't always the best approach when dealing with tables
> > that have row counts in the tens of millions and greater. These often
> > take hours to move.
>
> > Given what we're trying to do here, Does anyone have a better
> > suggestion as to how to handle this dynamically?
>
> > If anyone would like me to post the stord proc (it works quite well)
> > I'll be happy to do so.
>
> > Thanks
>
> > Carl- Hide quoted text -
>
> - Show quoted text -

Michael

Many thanks but the problem is that SELECT ... INTO creates a new
table. I need to populate data in existing tables without losing any
constraints, primary key settings, indices, etc. I want to move the
production data to dev/test and ONLY the data. The existing structures
on the target must remain as is.

Thanks

Carl

 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 3) Posted: Fri Jan 08, 2010 9:04 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 8, 11:57 am, Plamen Ratchev wrote:
> If you are using SQL Server 2008 then INSERT INTO can be minimally logged:http://blogs.msdn.com/sqlserverstorageengine/archive/2008/03/06/minim...http://blogs.msdn.com/sqlserverstorageengine/archive/2008/03/23/minim...
>
> --
> Plamen Ratchevhttp://www.SQLStudio.com

Plamen

We're on 2005. Anything I can do with this?

Thanks

Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 4) Posted: Fri Jan 08, 2010 9:27 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 8, 12:19 pm, Plamen Ratchev wrote:
> This is new to SQL Server 2008 so you cannot use it in SQL Server 2005...
>
> I agree with Andrew that generating change scripts for sync may be the most efficient option. Other alternatives are to
> look at BULK INSERT/BCP to import data.
>
> --
> Plamen Ratchevhttp://www.SQLStudio.com

You and Andrew make a good point. We'll try that out this afternoon.
We've been using the stord proc approach because we schedule it to run
weekly but some large DBs may require manual intervention

Thanks

Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Michael Coles

External


Since: Jan 08, 2010
Posts: 3



(Msg. 5) Posted: Fri Jan 08, 2010 11:08 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Have you considered SELECT ... INTO ... instead of INSERT INTO ... SELECT
FROM ...?


--
Thanks

Michael Coles
SQL Server MVP
Author, "Expert SQL Server 2008 Encryption"
(http://www.apress.com/book/view/1430224649)
----------------

"SetonSoftware" wrote in message

>I have a stored procedure that we've been using here for many months
> that allows us to migrate data from a production databse to test and
> dev so we always have fresh (and real) data to play with. I couldn't
> just backup/restore as I may have added new stored procs or new
> columns to the target tables and I don't want these overwritten. The
> solution was to create a data-driven stored proc that would iterate
> all the tables that the source and target have in common. Then, for
> each table, it would iterate all the columns that are in common to
> create a dynamic INSERT INTO...SELECT FROM statement that would list
> all the common fields.
>
> My question is how to handle very large tables. INSERT INTO...SELECT
> FROM works isn't always the best approach when dealing with tables
> that have row counts in the tens of millions and greater. These often
> take hours to move.
>
> Given what we're trying to do here, Does anyone have a better
> suggestion as to how to handle this dynamically?
>
> If anyone would like me to post the stord proc (it works quite well)
> I'll be happy to do so.
>
> Thanks
>
> Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Michael Coles

External


Since: Jan 08, 2010
Posts: 3



(Msg. 6) Posted: Fri Jan 08, 2010 11:09 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Meant to add a couple of references:
http://msdn.microsoft.com/en-us/library/ms188029.aspx
http://msdn.microsoft.com/en-us/library/ms191244.aspx

--
Thanks

Michael Coles
SQL Server MVP
Author, "Expert SQL Server 2008 Encryption"
(http://www.apress.com/book/view/1430224649)
----------------

"SetonSoftware" wrote in message

>I have a stored procedure that we've been using here for many months
> that allows us to migrate data from a production databse to test and
> dev so we always have fresh (and real) data to play with. I couldn't
> just backup/restore as I may have added new stored procs or new
> columns to the target tables and I don't want these overwritten. The
> solution was to create a data-driven stored proc that would iterate
> all the tables that the source and target have in common. Then, for
> each table, it would iterate all the columns that are in common to
> create a dynamic INSERT INTO...SELECT FROM statement that would list
> all the common fields.
>
> My question is how to handle very large tables. INSERT INTO...SELECT
> FROM works isn't always the best approach when dealing with tables
> that have row counts in the tens of millions and greater. These often
> take hours to move.
>
> Given what we're trying to do here, Does anyone have a better
> suggestion as to how to handle this dynamically?
>
> If anyone would like me to post the stord proc (it works quite well)
> I'll be happy to do so.
>
> Thanks
>
> Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Plamen Ratchev

External


Since: Aug 20, 2008
Posts: 672



(Msg. 7) Posted: Fri Jan 08, 2010 11:57 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Back to top
Login to vote
Andrew J. Kelly

External


Since: Sep 01, 2003
Posts: 551



(Msg. 8) Posted: Fri Jan 08, 2010 11:59 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

That process can get very complicated very fast and not to mention the time
consuming part for the updates as well. You might want to look into one of
the Database (& potentially data ) compare tools such as those from Apex or
Red-gate. Then you can generate a script to modify that will modify a newly
restored copy of prod to have the changes from the current dev db. This way
it will retain the sps and such you had in dev but not in prod.

--

Andrew J. Kelly SQL MVP
Solid Quality Mentors

"SetonSoftware" wrote in message

> I have a stored procedure that we've been using here for many months
> that allows us to migrate data from a production databse to test and
> dev so we always have fresh (and real) data to play with. I couldn't
> just backup/restore as I may have added new stored procs or new
> columns to the target tables and I don't want these overwritten. The
> solution was to create a data-driven stored proc that would iterate
> all the tables that the source and target have in common. Then, for
> each table, it would iterate all the columns that are in common to
> create a dynamic INSERT INTO...SELECT FROM statement that would list
> all the common fields.
>
> My question is how to handle very large tables. INSERT INTO...SELECT
> FROM works isn't always the best approach when dealing with tables
> that have row counts in the tens of millions and greater. These often
> take hours to move.
>
> Given what we're trying to do here, Does anyone have a better
> suggestion as to how to handle this dynamically?
>
> If anyone would like me to post the stord proc (it works quite well)
> I'll be happy to do so.
>
> Thanks
>
> Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Plamen Ratchev

External


Since: Aug 20, 2008
Posts: 672



(Msg. 9) Posted: Fri Jan 08, 2010 12:19 pm
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This is new to SQL Server 2008 so you cannot use it in SQL Server 2005...

I agree with Andrew that generating change scripts for sync may be the most efficient option. Other alternatives are to
look at BULK INSERT/BCP to import data.

--
Plamen Ratchev
http://www.SQLStudio.com
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Michael Coles

External


Since: Jan 08, 2010
Posts: 3



(Msg. 10) Posted: Fri Jan 08, 2010 12:46 pm
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Yeah, there are several things you can do to increase performance but most
introduce some other restrictions or changes to your current process --
dropping constraints and indexes for instance. I'm with Andrew on this
one -- since you do this a lot it's probably in your best interest to look
into a third-party tool to compare and automatically synchronize database
structures and data.

--
Thanks

Michael Coles
SQL Server MVP
Author, "Expert SQL Server 2008 Encryption"
(http://www.apress.com/book/view/1430224649)
----------------
Michael

Many thanks but the problem is that SELECT ... INTO creates a new
table. I need to populate data in existing tables without losing any
constraints, primary key settings, indices, etc. I want to move the
production data to dev/test and ONLY the data. The existing structures
on the target must remain as is.

Thanks

Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 11) Posted: Fri Jan 08, 2010 8:26 pm
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

SetonSoftware (seton.software@verizon.net) writes:
> I have a stored procedure that we've been using here for many months
> that allows us to migrate data from a production databse to test and
> dev so we always have fresh (and real) data to play with. I couldn't
> just backup/restore as I may have added new stored procs or new
> columns to the target tables and I don't want these overwritten. The
> solution was to create a data-driven stored proc that would iterate
> all the tables that the source and target have in common. Then, for
> each table, it would iterate all the columns that are in common to
> create a dynamic INSERT INTO...SELECT FROM statement that would list
> all the common fields.

Keep your stored procedures under version control, and have a tool
that loads the files from the repository into the freshly restored
copy of the database.

--
Erland Sommarskog, SQL Server MVP, esquel DeleteThis @sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Geoff Schaller

External


Since: Jul 13, 2008
Posts: 58



(Msg. 12) Posted: Sat Jan 09, 2010 4:26 am
Post subject: Re: Moving large amount of data [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Carl,

So why aren't you just using replication?
This would have minimal performance impact and doubles as a backup.

Geoff




"SetonSoftware" wrote in message


> I have a stored procedure that we've been using here for many months
> that allows us to migrate data from a production databse to test and
> dev so we always have fresh (and real) data to play with. I couldn't
> just backup/restore as I may have added new stored procs or new
> columns to the target tables and I don't want these overwritten. The
> solution was to create a data-driven stored proc that would iterate
> all the tables that the source and target have in common. Then, for
> each table, it would iterate all the columns that are in common to
> create a dynamic INSERT INTO...SELECT FROM statement that would list
> all the common fields.
>
> My question is how to handle very large tables. INSERT INTO...SELECT
> FROM works isn't always the best approach when dealing with tables
> that have row counts in the tens of millions and greater. These often
> take hours to move.
>
> Given what we're trying to do here, Does anyone have a better
> suggestion as to how to handle this dynamically?
>
> If anyone would like me to post the stord proc (it works quite well)
> I'll be happy to do so.
>
> Thanks
>
> Carl
 >> Stay informed about: Moving large amount of data 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Select a row of data by Higher('xx') amount - If there are two or multiple rows of data (such as 'AcctNo', 'ShipDate', 'ShippingCharge') with exactly same 'AcctNo', 'ShipDate' and only difference is ShippingCharge, what is T-SQL query to bring in the row with higher ShippingCharge? I was trying t...

Moving data - I'm sure that this question has been asked hundred's of times but really don't know how to search for it. I have 3 fields that contain street address information. The fields are PrimaryAddress, PrimaryAddress2, PrimaryAddress3 I need to move..

Alternatives for Moving XML Data Into SQL Server - Several Web servers that I work with store runtime exception details [of Web sites] in XML files on the local disk subsystem [of each Web server] - one runtime exception per XML file. I would like to move the exception data from the XML files to SQL..

large scale data architecture question - any suggestion on designing a a database that hold large amount of records(hundreds of millions of records) if i have a table says user, that has hundred of millon records. how do I architect the table that it will not affect the searching performance?..

Issue with retrieving large data over web using Stored Pro.. - Hello. I moved my stored procedure and tables from SQL 2000 to SQL 2005. I am having an issue to retrieve a large amount of data using previous stored procedure (sp) over web (ASP page). Other sp works fine, but one sp that retrieves large amount of dat...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]