Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
titleLinked server - SQL
linenumberstrue
declare @linkedservername as nvarchar(100)
Set @linkedservername = '1.1.1.1\SQLSRV'

declare @dbname as nvarchar(100)
Set @dbname = 'EBIFlowDB'


DECLARE @sql nvarchar(MAX);
SET @sql='
INSERT INTO schPerson 
select * from ['+@linkedservername+'].'+@dbname+'.dbo.schPerson 
where Id not in (select Id from schPerson)

INSERT INTO schUser
select * from ['+@linkedservername+'].'+@dbname+'.dbo.schUser 
where Id not in (select Id from schUser)

INSERT INTO schEmployee
select * from ['+@linkedservername+'].'+@dbname+'.dbo.schEmployee 
where Id not in (select Id from schEmployee)

INSERT INTO schLocation
select * from ['+@linkedservername+'].'+@dbname+'.dbo.schLocation 
where Id not in (select Id from schLocation)

INSERT INTO schOrganizationalUnit
select * from ['+@linkedservername+'].'+@dbname+'.dbo.schOrganizationalUnit 
where Id not in (select Id from schOrganizationalUnit)

INSERT INTO schOrganizationalUnitMember
select * from ['+@linkedservername+'].'+@dbname+'.dbo.schOrganizationalUnitMember 
where Id not in (select Id from schOrganizationalUnitMember)
'

exec (@sql)

 

Ayrıca Bakınız

SQL Linked Servers nasıl kullanılır?