Simple example:
//Create Linkserver
exec sp_addlinkedserver ' srv_lnk ', ' ', ' SQLOLEDB ', ' Server name '
//Login Linkserver
exec sp_addlinkedsrvlogin ' Srv_lnk ', ' false ', NULL, ' username ', ' password '
//Query the table of linkserver database Databasea TableA
Select * from Srv_lnk. DataBaseA.dbo.TableA
//list The tables in the linked server
EXEC sp_tables_ex txtsrv
Here is the code that executes the pass,
--Execute here first
EXEC sp_addlinkedserver ' Xhlink ', ', ' SQLOLEDB ', ' 10.0.0.27 '
EXEC sp_addlinkedsrvlogin ' Xhlink ', ' false ', NULL, ' sa ', ' ****** '
--Execute here again, can't execute together
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 '
)
The above through two places to learn from, to detail can see the following two blog
http://blog.csdn.net/htl258/article/details/5695391
http://blog.csdn.net/postfxj/article/details/21405711
SQL Two database data inserts from different IPs,