create PROCEDURE [dbo].[sp_Syn_35BossIAPSalonData] AS
begin
if not exists(select 1 from master..sysservers where srvname= 'Serv35')
begin
exec sp_addlinkedserver 'Serv35', '', 'SQLOLEDB', '10.20.22.35'
exec sp_addlinkedsrvlogin 'Serv35', 'false' ,null, 'App_SynDataForSys', 'SynDataFors2005'
end
if(SELECT count(*) FROM Serv35.BossIAP.dbo.T_salon_youxiao)>0
begin
truncate table NewSMS.dbo.T_salon_youxiao
insert into NewSMS.dbo.T_salon_youxiao
select *
FROM Serv35.BossIAP.dbo.T_salon_youxiao
end
EXEC sp_droplinkedsrvlogin 'Serv35', NULL
exec sp_dropserver 'Serv35'
end
创建好存储过程后,先执行
if not exists(select 1 from master..sysservers where srvname= 'Serv35')
begin
exec sp_addlinkedserver 'Serv35', '', 'SQLOLEDB', '10.250.252.35'
exec sp_addlinkedsrvlogin 'Serv35', 'false' ,null, 'App_SynDataForSys', 'SynDataForSys201205'
end
再创建一个作业定期运行