跨服务器数据库拷贝数据

来源:互联网 发布:我的人工智能贾维斯 编辑:程序博客网 时间:2024/05/19 19:13

        就在刚才我做了一件很让人头痛的事,不知道大家有没有遇到过,就是一不小心把数据库中的某个表里的数据全删除了,本来是想通过过滤条件去删除一些不要的数据的,可是由于手速太快,条件还没有选中,就按下了F5 键,一下子不知道如何是好!最后我上网也找了一些方法去解决这样的问题,最终还是被我找到了!如下

 1.启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

2.执行数据的拷贝:
SQL语句实现跨Sql server数据库操作实例 - 查询远程SQL,本地SQL数据库与远程SQL的数据传递
(1)查询192.168.1.1的数据库(TT)表test1的数据
select * from opendatasource('sqloledb','server=192.168.1.1;uid=sa;pwd=123456;database=TT').TT.dbo.test1
(2)从192.168.1.2的数据库(TT)表test2插入192.168.1.1数据库(TT)的表test1去
insert into opendatasource('sqloledb','server=192.168.1.1;uid=sa;pwd=123456;database=TT').TT.dbo.test1 (id,[name],password) select id,[name],password
from opendatasource('sqloledb','server=192.168.1.2;uid=sa;pwd=123456;database=TT').TT.dbo.test2


3.为了安全使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

 

这样就完成了跨服务器进行数据的拷贝,相信这个方法肯定能帮助我们在更加有效的去操作数据库

 

原创粉丝点击