|
Next: Table variable
|
| Author |
Message |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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?)
|
|
|
|
|
| Back to top |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |
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 |
|
 |  |