求SQL 触发器代码:实现多个数据库下结构名称相同的多个表同步
在同一台服务器上,分别有DB_01和DB_02和和DB_03三个数据库,三个数据库里都有个结构名称完成一样的表AA;触发器实现DB_01数据库下AA表增加、修更、删除时同...
在同一台服务器上,分别有DB_01和DB_02和和DB_03三个数据库,三个数据库里都有个结构名称完成一样的表AA;
触发器实现DB_01数据库下AA表增加、修更、删除时同步更新DB_02和和DB_03数据库下的AA表,求高手帮写下代码最好直接可用的,谢谢!
楼上语法执行报错呀:在关键字 'begin' 附近有语法错误。 展开
触发器实现DB_01数据库下AA表增加、修更、删除时同步更新DB_02和和DB_03数据库下的AA表,求高手帮写下代码最好直接可用的,谢谢!
楼上语法执行报错呀:在关键字 'begin' 附近有语法错误。 展开
展开全部
begin前要加上as:
create trigger TR_DB01_AA_insert
on AA
for insert
as
begin
insert into DB_02..AA select * from inserted
insert into DB_03..AA select * from inserted
end
go
create trigger TR_DB01_AA_update
on AA
for update
as
begin
update a set
a.colA=b.colA ,
a.colB=b.colB
from DB_02..AA a,inserted b where a.id=b.id
update a set
a.colA=b.colA ,
a.colB=b.colB
from DB_03..AA a,inserted b where a.id=b.id
end
go
create trigger TR_DB01_AA_insert
on AA
for delete
as
begin
delete a from DB_02..AA a ,deleted b where a.id=b.id
delete a from DB_03..AA a ,deleted b where a.id=b.id
end
create trigger TR_DB01_AA_insert
on AA
for insert
as
begin
insert into DB_02..AA select * from inserted
insert into DB_03..AA select * from inserted
end
go
create trigger TR_DB01_AA_update
on AA
for update
as
begin
update a set
a.colA=b.colA ,
a.colB=b.colB
from DB_02..AA a,inserted b where a.id=b.id
update a set
a.colA=b.colA ,
a.colB=b.colB
from DB_03..AA a,inserted b where a.id=b.id
end
go
create trigger TR_DB01_AA_insert
on AA
for delete
as
begin
delete a from DB_02..AA a ,deleted b where a.id=b.id
delete a from DB_03..AA a ,deleted b where a.id=b.id
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询