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.如果后期有数据库修改了密码,可通过页面修改远程链接