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

方法一:

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))