sybase复制服务

来源:互联网 发布:台达plc编程教学视频 编辑:程序博客网 时间:2024/05/22 06:39

Sybase复制服务器表的单向复制和双向复制定义语句

单向复制

一、在hn01_db上新建表tab1

isql -Usa -P -Shn01

1> use hn01_db

2> create table tab10(a int, b char(10), c int)

3> go

1> sp_setreplicate tab10, true

2> go

The replication status for 'tab10' is set to true.

(return status = 0)

1> grant all on tab10 to public

2> go

1>

二、在hn02_db上新建表tab1

isql -Usa -P -Shn02

1> use hn02_db

2> create table tab10(a int, b char(10), c int)

3> go

1> sp_setreplicate tab10, true

2> go

The replication status for 'tab10' is set to true.

(return status = 0)

1> grant all on tab10 to public

2> go

1>

三、在HN01_REP建立复制关系

isql -Usa -P -SHN01_REP

1> create replication definition rep_tab10 with primary at hn01.hn01_db

2> with all tables named 'tab10' (a int, b char(10), c int) primary key(a)

3> go

Replication definition 'rep_tab10' is created.

1> create subscription sub_tab10 for rep_tab10 with replicate at hn02.hn02_db

2> go

Subscription 'sub_tab10' is in the process of being created.

1>

四、测试

1、在hn01_db里tab1表中插入一条数据

1> insert into tab10 values(1, "AAAAA", 1)

2> go

(1 row affected)

1> select * from tab10

2> go

a b c

----------- ---------- -----------

1 AAAAA 1

(1 row affected)

1>

2、检查hn02_db里tab1表,看是否相应增加一条数据

1> select * from tab10

2> go

a b c

----------- ---------- -----------

1 AAAAA 1

(1 row affected)

1>

五、注意

1、建表时不要把多条命令放到一起写在运行GO,会把表写到master库中去

双向复制

一、hn01添加表

isql -Usa -P -Shn01

1> use hn01_db

2> go

1> create table tab4 (a int, b char(10), c int)

2> go

1> sp_setreplicate tab4, true

2> go

The replication status for 'tab4' is set to true.

(return status = 0)

1> grant all on tab4 to public

2> go

二、hn02添加表

isql -Usa -P -Shn02

1> use hn02_db

2> go

1> create table tab4 (a int, b char(10), c int)

2> go

1> sp_setreplicate tab4, true

2> go

The replication status for 'tab4' is set to true.

(return status = 0)

1> grant all on tab4 to public

2> go

三建议双向复制关系

isql -Usa -P -SHN01_REP

1> create replication definition hn01_tab4 with primary at hn01.hn01_db

2> with all tables named 'tab4'(a int, b char(10), c int)

3> primary key (a) searchable columns (a)

4> go

Replication definition 'hn01_tab4' is created.

1> create subscription sub_hn01_tab4 for hn01_tab4

2> with replicate at hn02.hn02_db

3> go

Subscription 'sub_hn01_tab4' is in the process of being created.

1> create replication definition hn02_tab4 with primary at hn02.hn02_db

2> with all tables named 'tab4'(a int, b char(10), c int)

3> primary key (a) searchable columns (a)

4> go

Replication definition 'hn02_tab4' is created.

1> create subscription sub_hn02_tab4 for hn02_tab4

2> with replic

ate at hn01.hn01_db

3> go

Subscription 'sub_hn02_tab4' is in the process of being created.

1>

四、测试

1、检查hn01上tab4表空,插入一条数据

1> select * from tab4

2> go

a b c

----------- ---------- -----------

(0 rows affected)

1> insert into tab4 values(1, "AAAAA", 1)

2> go

(1 row affected)

1>

2、检查hn02上tab4表是否相应追加了一条数据

1> select * from tab4

2> go

a b c

----------- ---------- -----------

1 AAAAA 1

(1 row affected)

1>

3、在hn02上tab4插入一条数据

1> insert into tab4 values(2, "AAAAA", 1)

2> go

(1 row affected)

1> select * from tab4

2> go

a b c

----------- ---------- -----------

1 AAAAA 1

2 AAAAA 1

(2 rows affected)

1>

2、检查hn01上tab4表是否相应追加了一条数据

1> select * from tab4

2> go

a b c

----------- ---------- -----------

1 AAAAA 1

2 AAAAA 1

(2 rows affected)

1>

0 0