两个数据库服务器复制数据:
--创建链接服务器 exec sp_addlinkedserver ‘ITSV‘ , ‘‘ , ‘SQLOLEDB‘ , ‘192.168.1.10‘ exec sp_addlinkedsrvlogin ‘ITSV‘ , ‘false‘ , null , ‘sa‘ , ‘sa@1234‘
--执行存储过程
exec batch_import ‘001‘
--单独处理"zsb_rvinfo"表
delete from zsb_rvinfo
insert into zsb_rvinfo select * from ITSV.DBName.dbo.zsb_rvinfo
--以后不再使用时删除链接服务器
exec sp_dropserver ‘ITSV‘, ‘droplogins‘
--跨服务器复制单表数据 insert into zsb_rvinfo select TOP (20000) * from openrowset(‘sqloledb‘,‘192.168.1.10‘;‘sa‘;‘sa@1234‘,‘select * from ..zsb_rvinfo‘)
其他相关
--数据存入临时表 select * into ##TempTable from ITSV.DBName.dbo.zsb_customer --多条id相同的数据,取日期最新的 select * from zsb_customer t where not exists (select 1 from zsb_customer where id=t.id and 日期>t.日期) -- 定义游标. DECLARE @ctm_id VARCHAR(10); DECLARE customer_fast CURSOR FAST_FORWARD FOR SELECT ctm_id FROM res_zsb_customer; -- 打开游标. OPEN customer_fast; WHILE 1=1 BEGIN -- 填充数据. FETCH NEXT FROM customer_fast INTO @ctm_id; if(@ctm_id != ‘‘) -- 假如未检索到数据,退出循环. IF @@fetch_status!= 0 BREAK; --PRINT @value; END;
原文地址:https://www.cnblogs.com/mapstar/p/12174636.html
时间: 2024-11-01 04:54:08