码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server实现跨库查询(跨库select insert)

时间:2015-07-30 11:10:24      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

方法一:

select  * from servername.dbo.tablename

方法二:

select * from OPENDATASOURCE(
         ‘SQLOLEDB‘,
         ‘Data Source=远程ip;User ID=sa;Password=密码‘
         ).库名.dbo.表名
where 条件

select top 100 * from OPENDATASOURCE(
         ‘SQLOLEDB‘,
         ‘Data Source=192.168.6.100;User ID=sa;Password=1234‘
         ).[zhaolx-test].dbo.TGongwen

where gid <5

insert into OPENDATASOURCE(
         ‘SQLOLEDB‘,
         ‘Data Source=192.168.6.100;User ID=sa;Password=1234‘
         ).[zhaolx-test].dbo.t_aaa (id ,name )values(‘001‘,‘Tom‘)

select top 100 * from OPENDATASOURCE(
         ‘SQLOLEDB‘,
         ‘Data Source=192.168.6.100;User ID=sa;Password=1234‘
         ).[zhaolx-test].dbo.t_aaa

SQL Server实现跨库查询(跨库select insert)

标签:

原文地址:http://www.cnblogs.com/panshengqiang/p/4688519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!