Click here to Skip to main content
15,885,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a table X on DB A which has 79 million records.
I want to transfer these records to DB B table Y.
When I run the insert statement, it fails. Also it is observed that CPU utilization is high that time.
How can I achieve this using SQL Server?


Thanks,
Lok.

What I have tried:

I tried insert select but it fails.
Posted
Updated 30-Jun-18 22:30pm
Comments
[no name] 28-Jun-18 9:33am    
Have a look here, accepted answer, Option 2 sounds good to me:
sql - Transfer data from one database to another database - Stack Overflow[^]
RedDk 28-Jun-18 14:16pm    
I want to know what the exact error message from SQL Server was. Every line of it. Substitution of sensitive terms excepted.
[no name] 28-Jun-18 15:10pm    
Did you insert "any" records?

1 solution

79 million is quite a amount. Though you can try following things-
1. Go with scripting (still I think, it'd fail)
2. Go with SELECT * INTO statement
SQL
SELECT * INTO [db-name].new-table-name
FROM [db-name].table-name [WHERE condition]

You can try to insert few records at a time and follow the same again. I'd suggest you to use ROW_NUMBER[^] and WHILE loop to give it a go.

I have done with around 83K records

KR
 
Share this answer
 
Comments
Maciej Los 2-Jul-18 3:05am    
5ed!
Lokesh Zende 5-Jul-18 0:37am    
Yes. I did using WHILE.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900