nynw.net
当前位置:首页 >> sql 触发器 获取插入的记录 转存到另一个数据库的表 >>

sql 触发器 获取插入的记录 转存到另一个数据库的表

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 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 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...

--创建测试表create table t_a(id int,name varchar(10));create table t_b(id int,name varchar(10));--测试数据insert into t_a(id,name) values (1,'a');--创建 for delete 触发器create trigger trg_t_a_1 on t_afor deleteasbegininsert in...

create trigger in_table on aaa after insert as begin insert into bbb(b1,b2) select a1,a2 from inserted end

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

/*1 tg_in*/ after insert update e set eage=case when e.ed='xx' then 'xx' else 'xx' end from e,i where e.id=i.id /*2 tg_up*/ after update if update(ed) update e set eage=case when e.ed='xx' then 'xx' else 'xx' end from e,inserte...

很简单. 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; 触发器比较经典的用法,百度就一大堆.

在触发器中有2个表,inserted,deleted inserted表:用来存储INSERT和UPDATE语句所影响的行的副本。意思就是在inserted表中临时保存了被插入或被更新后的记录行。在执行 INSERT 或UPDATE 语句时,新加行被同时添加到inserted表和触发器表中。因此...

如下: CREATE TRIGGER del_kh ON dbo.卡信息表 AFTER DELETE AS insert into 作废卡信息表(kh,xm,xb,kmc,sjhm,sysycs,fxrq,dqrq) select kh,xm,xb,kmc,sjhm,sysycs,fxrq,dqrq from deleted ==== 触发器激活时,会把删除的记录放在deleted临时表...

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