簡單的兩庫同步觸發器

2021-04-12 16:52:18 字數 754 閱讀 5288

create database b

gouse b

gocreate table man(a int, b int, c int, d int)

go--

create database a

gouse a

gocreate table man(a int, b int, c int)

create trigger tr_man_delete on man

for delete

asdelete tmpb

from deleted a, b.dbo.man tmpb

where a.a=tmpb.a and a.b=tmpb.b and a.c=tmpb.c

gocreate trigger tr_man_insert on man

for insert

asinsert b.dbo.man

select *, 1 from inserted

gocreate trigger tr_man_update on man

for update

asupdate b.dbo.man tmpb set tmpb.a=inserted.a, tmpb.b=inserted.b, tmpb.c=inserted.c

from inserted, deleted

where tmpb.a=deleted.a and tmpb.b=deleted.b and tmpb.c=deleted.c

go

觸發器實現跨庫同步

如果只是簡單的資料同步,可以用觸發器來實現.下面是例子 測試環境 sql2000,遠端主機名 xz,使用者名稱 sa,密碼 無,資料庫名 test 建立測試表,不能用標識列做主鍵,因為不能進行正常更新 在本機上建立測試表,遠端主機上也要做同樣的建表操作,只是不寫觸發器 if exists selec...

簡單的觸發器

定義 何為觸發器?在sql server裡面也就是對某乙個表的一定的操作,觸發某種條件,從而執行的一段程式。觸發器是乙個特殊的儲存過程。常見的觸發器有三種 分別應用於insert update delete 事件。表一 news表 create table dbo news id int ident...

觸發器學習《一》 簡單觸發器建立

1 建立表 create table userinfo id number 10,0 primary key,name varchar2 40 2 建立序列 create sequence userinfo seq start with 1 maxvalue 9999999999 increment...