nynw.net
当前位置:首页 >> sql中用触发器更新另一张表的数据 >>

sql中用触发器更新另一张表的数据

create trigger tr_Sale_MerchInfo on Sale after insert, updateasbegin declare @num int , @MerchID int select @num = SaleNum, @MerchID = MerchID from inserted update MerchInfo set MerchNum = MerchNum - @num where MerchID = @Merch...

假设有两张表,一张为操作记录表tbA(MyID,MyX,MyY),一张为账户余额表tbB(MyID,MySum) MyID:int类型 MyX:money类型 MyY:int类型(-1取钱,1存钱) MySum:money类型 我想在我记录存入多少钱的同时,在余额表里的MySum里的数据也更着改变,而我们也不需要...

CREATE TRIGGER a1_a ON [dbo].[a1] FOR INSERT AS insert into b.dbo.b1(g,h,j) select c as g,d as h,e as j from inserted 在A数据库A1表,加上面的触发器(只限于同一台服务器不通数据库数据转存),如果要在不同的服务器上,就先在A所在服...

很简单. reate or replace trigger tri_name after update on 表的名字 for each row begin if Userstate=0 then update 另外一个表 set UserState = '0'; dbms_output.put.line('已改变'); else null; end; 触发器比较经典的用法,百度就一大堆.

--创建多表更新触发器(trg_class_Update) create Trigger [dbo].[trg_class_Update] On [dbo].[class] after update As if update(cid) --变更cid时触发 begin update product set pcid=I.cid from product as B,deleted D, inserted as I where...

这个你得建插入、删除和更新三种触发器。 create trigger tr_in_选课表 on 选课表 FOR INSERT as update 课程表 set 选课人数=选课人数+1 where 课程编号=(select 课程编号 from inserted) go --删除的,删除时那就要减1 create trigger tr_del_...

说明: 1、只标记了 update,没有标记insert 2、假定 userid,gga,ggb 是int类型,你改成相应的类型 create trigger TriggerName on ABC after upate as begin -- declare @useridNew int; declare @ggaNew int; declare @ggbNew int; -- select ...

create trigger tgr_name on 表a for insert as declare @id select @id=id from inserted update 表b set State=0 where State=1 and id=@id

CREATE TRIGGER 触发器名字 ON 你的那种主表 FOR DELETE AS BEGIN DELETE FROM 你的那张子表 WHERE 子表的关联主表ID IN ( SELECT 主表ID FROM deleted ); END; go

表结构 create table MyUser ( UserName nvarchar(50) primary key, PassWord nvarchar(50), state int ) //触发器 create trigger [MyUser_trigger] on [dbo].[MyUser] for insert,delete as begin if exists ( select * from sysobjects where...

网站首页 | 网站地图
All rights reserved Powered by www.nynw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com