如何备份部分表记录到另一台机器
2024-07-21 02:07:05
供稿:网友
-- 建立链接服务器,并提供登录信息
-- 请修改 @datasrc 为备份服务名
exec sp_addlinkedserver @server='backupserver', @srvproduct='', @provider='sqloledb', @datasrc='servercomputername'
go
-- 请修改 @rmtuser、@rmtpassword 参数为备份服务器sql server登录帐号
exec sp_addlinkedsrvlogin @rmtsrvname='backupserver',@useself='false',@locallogin=null,@rmtuser='sa',@rmtpassword='pass'
go
-- 把数据保存到备份服务器
-- dbname应修改备份服务器数据库名
insert into backupserver.dbname.dbo.mastertable
select * from mastertable
where keyfield in ('value1','value2')
go
insert into backupserver.dbname.dbo.mastertabledetail
select * from mastertabledetail
where (select keyfield from mastertable where mastertabledetail.mastertableid=mastertable._id) in ('value1','value2')
go
-- 删除本数据库记录
delete from mastertable
where keyfield in ('value1','value2')
go
delete from mastertabledetail
where (select keyfield from mastertable where mastertabledetail.mastertableid=mastertable._id) in ('value1','value2')
go
中国最大的web开发资源网站及技术社区,