急!郁闷!表同步使用触发器的问题

pgwron 2006-04-13 03:42:05
有同太机器有2个数据库,有几个表要实时同步,表结构相同,其中id为自增字段,我写好触发器,2边表同时加上触发器就有错误,只反再一边的表就时好的,请大家帮我看看,哪里有问题
表1的触发器
create TRIGGER Web_Insert on Web.dbo.表1
for Insert
as
if not exists(select sid from OA.dbo.表1 where sid =(select id from inserted) )
begin
insert into OA.dbo.表1
(sid,Name,corid,password,city,industry,link,fax,address,code,
tel,email,licen,time,memo,Flag,Submit)

select id,Name,corid,password,city,industry,link,fax,address,code,
tel,email,licen,time,memo,Flag,Submit from inserted
end
表2的触发器
create TRIGGER OA_Insert on OA.dbo.表1
for Insert
as
if not exists(select sid from Web.dbo.表1 where sid =(select id from inserted) )

begin
insert into Web.dbo.表1
(sid,Name,corid,password,city,industry,link,fax,address,code,
tel,email,licen,time,memo,Flag,Submit)

select id,Name,corid,password,city,industry,link,fax,address,code,
tel,email,licen,time,memo,Flag,Submit from inserted
end
...全文
184 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pgwron 2006-04-13
  • 打赏
  • 举报
回复
问题解决,谢谢楼上2位,最后是把判断删除,设置的不允许嵌套触发
pgwron 2006-04-13
  • 打赏
  • 举报
回复
还是报错。错误是,已超出每个查询可使用的数据库数目的最大值,最大值为8

........我好像没有用到那么多数据库啊
pgwron 2006-04-13
  • 打赏
  • 举报
回复
不是啊。。sid就是存放的零一张表的id,是判断id是否存在,如果不存在才执行的啊
Yang_ 2006-04-13
  • 打赏
  • 举报
回复
记得服务器有个设置项,可以不允许嵌套触发的,我不记得具体了,你差下帮助文件
Yang_ 2006-04-13
  • 打赏
  • 举报
回复
互相触发了
就像死循环一样

gahade 2006-04-13
  • 打赏
  • 举报
回复

if not exists(select sid from Web.dbo.表1 where sid =(select id from inserted) )
应该是有问题的,因为inserted进来的时候是一批数据,你用=号不可以,可以用个游标,每行取,然后再判断相不相等!
gahade 2006-04-13
  • 打赏
  • 举报
回复
用这种方法试试:
insert into Web.dbo.表1(sid,Name,corid,password,city,industry,link,fax,address,code,tel,email,licen,time,memo,Flag,Submit)

select id,Name,corid,password,city,industry,link,fax,address,code,tel,email,licen,time,memo,Flag,Submit from inserted
where inserted.id not in (elect sid from Web.dbo.表1)
pgwron 2006-04-13
  • 打赏
  • 举报
回复
.....没有人么
pgwron 2006-04-13
  • 打赏
  • 举报
回复
大侠们!!帮我看看啊!

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧