Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to code to copy new records from one table

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-05-26 : 11:59:51
How to code to copy new records from tableA in remote server to tableB in local server?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-05-26 : 12:22:24
assuming you have linked servers set up:

insert into TableB (col1, col2)
select t1.col1, t1.col2
from server1.db1.ownername1.tableA t1
left join server2.db2.ownername2.tableb t2 on t1.col1 = t2.col1
where t2.col1 is null


Go with the flow & have fun! Else fight the flow
Go to Top of Page

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2005-05-26 : 12:23:11
INSERT INTO Target
SELECT * FROM Source S
WHERE NOT EXISTS (SELECT 'X' FROM Target T
WHERE S.PK = T.PK)
Go to Top of Page

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2005-05-26 : 12:23:41
you're too quick spirit1

/** sql sui generis **/
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-05-26 : 12:37:29
Thank you. I'll try both ways. If I want to copy more than one tables, how to code?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-05-26 : 12:38:28
one insert for each table.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-05-27 : 10:06:41
I test them but I do not which way is fast since I only test about 100 records.
Go to Top of Page
   

- Advertisement -