lwmc.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里的數據也更著改變,而我們也不需要...

很簡單. 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; 觸發器比較經典的用法,百度就一大堆.

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所在服...

CREATE TRIGGER 觸發器名字 ON 你的那種主表 FOR DELETE AS BEGIN DELETE FROM 你的那張子表 WHERE 子表的關聯主表ID IN ( SELECT 主表ID FROM deleted ); END; go

--創建多表更新觸發器(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 insert_table --創建觸發器,觸發器名稱 insert_table on tablea --哪個表的觸發器for insert --哪個動作觸發as declare @a varchar(100) --定義一個參數 select @a=id from inserted --取插入數據中的id update tableb set n=n+...

create trigger tr_零售表 on 零售表 for insert as begin declare @會員卡號 varchar(30),@交易金額 decimal(18,2) select @會員卡號=會員卡號,@交易金額=交易金額 from inserted update 會員表 set 本次積分=本次積分+cast(@交易金額/10 as in...

表結構 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...

create trigger T_updateA on A for update as if update(b) begin update B set B.b = inserted.b from inserted where B.a = inserted.a -- where 條件是假設的,你自己去寫 end

網站首頁 | 網站地圖
All rights reserved Powered by www.fpyfpq.tw
copyright ©right 2010-2021。
內容來自網絡,如有侵犯請聯系客服。[email protected]
加拿大快乐8开奖网站