Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

sql table record copy

MS SQL Server 2008

How do you script via a Stored Procedure the following:

DB 1 - Table 1A (server A)
DB 2 - Table 2A (server B)

if   DB 1 - Table 1A (column1) - unique value (uniqueidentity) doe not exist in
DB 2 - Table 2A (column1) - unique value (uniqueidentity) then create it in  DB 2 - Table 2A

then copy certain columns from DB 1 - Table 1A to DB 2 - Table 2A (insert a new entry).

(there could for example none, 1 or 1000's of new table entries to create/insert each time stored procedure is called)
ASKER CERTIFIED SOLUTION
Avatar of tigin44
tigin44
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amillyard

ASKER

tigin44: thanks for the feedback.  how do you llink servers?

 (1 db is on a dedicated and other on a public shared cloud environment for example).
you can create a linked server like the one below

EXEC sp_addlinkedserver  
   @server='lsserverA',
   @srvproduct='',
   @provider='SQLNCLI',
   @datasrc='Server1.abc.com\DB1'
tigin44:  does it matter which db server to run that script?   is this link preserved upon a physical reboot of server?
I assume that you will run this code on ServerB ... you can run it vice versa but you should change the linked server and references to the new definitions to run it on ServerA...