sqlserver的openquery配置

1.命令Demo

---openquery

--开启Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'Ad Hoc Distributed Queries',1

reconfigure

--关闭Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句

exec sp_configure 'Ad Hoc Distributed Queries',0

reconfigure

exec sp_configure 'show advanced options',0

reconfigure

--这句是映射一个远程数据库

exec sp_addlinkedserver   'LHGZPT', '', 'SQLOLEDB', '202.96.25.49,1433'

--这句是登录远程数据库

exec sp_addlinkedsrvlogin 'LHGZPT','false ',null, 'sino', '1qaz!QAZ'

--将另一个库中查询到的数据保存在本地库中

insert into lh_applyinfo(id,applyid,applytype,applystatus)

select * from openquery(LHGZPT,'SELECT id,applyid,applytype,applystatus FROM lhgzpt_nei.dbo.lh_applyinfo with(nolock) where create_date between ''2018-07-01 00:00:01'' and ''2018-10-31 23:00:01'' ')

--以后不再使用时删除链接服务器

exec sp_dropserver  'ITSV ', 'droplogins '

2.解决自增主键问题

--允许将显式值插入表的标识列中 ON-允许 OFF-不允许

set identity_insert OrderList ON--打开

insert into OrderList(id,ordername,createdate)

values(4520,'set',getdate())

set identity_insert OrderList OFF--关闭

3.如果后期有数据库修改了密码,可通过页面修改远程链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小安于乱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值