简单示例:
//创建linkServer
exec sp_addlinkedserver ‘srv_lnk‘,‘‘,‘SQLOLEDB‘,‘服务器名‘
//登陆linkServer
exec sp_addlinkedsrvlogin ‘srv_lnk‘,‘false‘,null,‘用户名‘,‘密码‘
//查询linkServer的数据库DataBaseA的表TableA
Select * From srv_lnk.DataBaseA.dbo.TableA
//List the tables in the linked server
EXEC sp_tables_ex txtsrv
下面是执行通过的代码,
--先执行这里
EXEC sp_addlinkedserver ‘XHLink‘,‘‘,‘SQLOLEDB‘,‘10.0.0.27‘
EXEC sp_addlinkedsrvlogin ‘XHLink‘,‘false‘,null,‘sa‘,‘******‘
--再执行这里,不能一起执行
insert into xh
SELECT * FROM XHLink.marketing.dbo.xh
where xh_bm=‘0607‘ and xh_rq=‘2015/01/03‘
insert into xhmx
SELECT * FROM XHLink.marketing.dbo.xhmx
where xhmx_dh in
(
SELECT xh_dh FROM XHLink.marketing.dbo.xh
where xh_bm=‘0607‘ and xh_rq=‘2015/01/03‘
)
以上通过两个地方学习而来,要详细可以看下面两个博客
http://blog.csdn.net/htl258/article/details/5695391
http://blog.csdn.net/postfxj/article/details/21405711