SQL SERVER创建连接服务器
EXEC master.dbo.sp_addlinkedserver @server = N'连接服务器名称', @srvproduct=N'sqlserver', @provider=N'SQLNCLI', @datasrc=N'连接服务器IP地址'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'连接服务器名称',@useself=N'False',@locallogin=NULL,@rmtuser=N'sa',@rmtpassword='数据库sa账户密码'
declare @Idcard varchar(18);
DECLARE cursor_name CURSOR FOR --定义游标
select Idcode from APIAPI
OPEN cursor_name --打开游标
FETCH NEXT FROM cursor_name INTO @Idcard --抓取下一行游标数据
WHILE @@FETCH_STATUS = 0
BEGIN
--PRINT '用户ID:'+@UserId+' '+'用户名:'+@username
if not exists (select Idcode from API_HealthCard where Idcode = @Idcard)
BEGIN
insert into API_HealthCard select top 1 * from APIAPI where Idcode = @Idcard
PRINT '刷新数据:' + @Idcard
END
--else
-- print '已存在:'+ @Idcard
FETCH NEXT FROM cursor_name INTO @Idcard
END
CLOSE cursor_name --关闭游标
DEALLOCATE cursor_name --释放游标
一个自由.NET开发者
bingqiang1903@gmail.com
https://www.cnblogs.com/sunbingqiang/