因公司产品及客户都是使用mysql、oracle数据库,很久没有使用sql server数据库了,今天使用时已经忘记sql server跨服务器查询、插入怎么写了,以下作一下备忘记录下来,以后可能还会用到;
--1.开启Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
Insert into SysLoginLog select * from openrowset('SQLOLEDB','sql服务器名';'用户名';'密码',数据库名.dbo.表名) t where t.LoginTime>'2017-01-01 00:00:000';
--2.关闭Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure