在下例中,企业有五台服务器:服务器 A、服务器 B、服务器 C、服务器 D 和服务器 E。服务器 B 是源服务器,在该服务器上执行和复制日志的备份和还原。服务器 C、服务器 D和服务器 E 包含目的数据库,而服务器 B 的日志备份将还原到目的数据库,以保持这些服务器与服务器 B 同步。服务器 A 是监视服务器,在该服务器上监视整个企业内的日志传送。每台目的服务器或源服务器只由一台监视服务器维护。数据库维护计划向导用于定义服务器 B 备份日志备份的时间与服务器 C、D 和 E 必须还原日志备份的时间之间的适当延迟。如果延迟超出了定义的时间,服务器 A 将使用 SQL Server 代理程序生成警报。该警报助于诊断目的服务器还原备份失败的原因。
不要将监视服务器作为源服务器,因为监视服务器用于维护关于日志传送系统的关键信息。应定期备份监视服务器。保持监视服务器独立对性能也有益,因为监视会增加不必要的开销。而且,源服务器作为支持生产工作负荷的服务器,最有可能出现故障,从而使监视中断。源服务器和目的服务器可以位于同一台计算机上。但在这种情况下,SQL Server 2000 故障转移群集可能提供更好的结果。有关更多信息,请参见故障转移群集。
if exists (select * from dbo.sysobjects where id = object_id(N'[test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [test]
go
create table test(id int not null constraint PK_test primary key
,name varchar(10))
go
use test1
go
if exists (select * from dbo.sysobjects where id = object_id(N'[test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [test]
go
create table test(id int identity(1,1) primary key
,name varchar(10))
go
--创建同步的触发器(仅test1上需要)
create trigger t_test on test
for insert,update,delete
as
set XACT_ABORT on
begin tran
delete from test2..test
where id in(select id from deleted)
insert into test2..test
select * from inserted
commit tran
go
--插入数据测试
insert into test
select 1,'aa'
union all select 2,'bb'
union all select 3,'c'
union all select 4,'dd'
union all select 5,'ab'
union all select 6,'bc'
union all select 7,'ddd'
--删除数据测试
delete from test where id in(1,4,6)
--更新数据测试
update test set name=name+'_123' where id in(3,5)
--显示测试的结果
select * from test a
full join test2..test b on a.id=b.id
--3.实现同步处理
--在srv1中创建如下的同步处理存储过程
create proc p_process
as
--更新修改过的数据
update b set name=i.name,telphone=i.telphone
from srv2.库名.dbo.author b,author i
where b.id=i.id and
(b.name<>i.name or b.telphone<>i.telphone)
--插入新增的数据
insert srv2.库名.dbo.author(id,name,telphone)
select id,name,telphone from author i
where not exists(
select * from srv2.库名.dbo.author where id=i.id)
--删除已经删除的数据(如果需要的话)
delete b
from srv2.库名.dbo.author b
where not exists(
select * from author where id=b.id)
go