Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiently moving large sets of data between SQL Server tables?

I have a rather large (many gigabytes) table of data in SQL Server that I wish to move to a table in another database on the same server.

The tables are the same layout.

What would be the most effecient way of going about doing this?

This is a one off operation so no automation is required.

Many thanks.

like image 546
Martin Avatar asked Nov 24 '08 14:11

Martin


People also ask

How can I transfer bulk data from one table to another in SQL Server?

Right-click on the database and choose Tasks/Export Data. A wizard will take you through the steps but you choosing your SQL server client as the data source and target will allow you to select the database and table(s) you wish to transfer.

How do I fetch more than 1000 records in SQL?

To query more than 1000 rows, there are two ways to go about this. Use the '$offset=' parameter by setting it to 1000 increments which will allow you to page through the entire dataset 1000 rows at a time.

How does SQL Server handle large amounts of data?

The most recommended and best option is to have a STANDBY server, restore the backup of the production database on that server, and then run the DBCC command. If the consistency checks run ok on the standby database, the production database should be ok as it is the source of the standby.


2 Answers

If it is a one-off operation, why care about top efficiency so much?

SELECT * INTO OtherDatabase..NewTable FROM ThisDatabase..OldTable

or

INSERT OtherDatabase..NewTable
SELECT * FROM ThisDatabase..OldTable

...and let it run over night. I would dare to say that using SELECT/INSERT INTO on the same server is not far from the best efficiency you can get anyway.

like image 140
Tomalak Avatar answered Sep 18 '22 12:09

Tomalak


Or you could use the "SQL Import and Export Wizard" found under "Management" in Microsoft SQL Server Management Studio.

like image 42
Vinblad Avatar answered Sep 18 '22 12:09

Vinblad