求写一个update触发器

[复制链接]
查看11 | 回复2 | 2009-7-3 16:36:04 | 显示全部楼层 |阅读模式
两张表主表:drug_info,从表: cpa_drug。其中主表的pzwh和从表的batch_no字段相关联。主表的pzwh字段改变的时候从表中的bathc_no字段也要改变,并且当主表xh_code的字段改变的时候从表中frug_no的字段也要改变,保留没有改变的数据!怎么写触发器啊?我写了个存储过程,不过,查询速度无法令我满意!查了十多分钟都没查出来!各位救救我吧!
create procedure pro_gxcd
as
update testcpa_drug
set testcpa_drug.drug_code=testdrug_info.xh_code
from testdrug_info
where testdrug_info.pzwh=testcpa_drug.standard_id
go

回复

使用道具 举报

千问 | 2009-7-3 16:36:04 | 显示全部楼层
create trigger teston drug_infofor updateasdeclare @oldno intdeclare @newno intdeclare @oldcode intdeclare @newcode intselect @oldno=pzwh,@oldcode=xh_code from deletedselect @newno=pzwh,@newcode=xh_code from inserted if @oldno @newno beginupdate cpa_drug set bathc_no=@newno where bathc_no=@oldnoend...
回复

使用道具 举报

千问 | 2009-7-3 16:36:04 | 显示全部楼层
前触发器吧...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行