Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Frnds,
I need to transfer datas from one database table to another database table.How to write query for that.
Posted

 
Share this answer
 
Comments
Thanks7872 25-Jul-13 7:26am    
Excellent.↑voted. Well,Sql bulk copy can be worth noting here which i suggested.
Maciej Los 25-Jul-13 7:57am    
Thank you ;)
Refer to these links

SqlBulkCopy Class[^]

SQL Bulk Copy with C#.Net[^]

Transferring Data Using SqlBulkCopy[^]

This concept will help you even with the large amount of data.

[Update]:Example
SQL
insert into table1
select * from table2
where table2.xyzid not in(select xyzid from table1)

And more options can be found here

SQL Server copy all rows from one table into another i.e duplicate table[^]

Regards..:laugh:
 
Share this answer
 
v3
Comments
Maciej Los 25-Jul-13 8:04am    
A 4! Good idea to copy data using C#. Useless if OP wants to move/copy data using T-SQL ;(
Please, improve your answer and i'll promise to up-vote ;)
Thanks7872 25-Jul-13 8:15am    
Agree.Answer updated.Big Respect.
Maciej Los 25-Jul-13 8:18am    
Up-voted!
Thank you and the same to you.
Thanks7872 25-Jul-13 8:19am    
Thanks Maciej.
Try this :

SQL
INSERT INTO DATABASE2.DBO.TABLEX(FIELD1, FIELD2, ...)
SELECT FIELD1, FIELD2, ... FROM DATABASE1.DBO.TABLEX

-- NOT FIELD LIST MUST BE SAME FOR BOTH TABLES
 
Share this answer
 

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