触发器问题 当表a中插入一条数据时。把插入的数据存入b表中 怎么写呀????求帮助
答案:3 悬赏:50 手机版
解决时间 2021-02-27 16:43
- 提问者网友:山高云阔
- 2021-02-27 02:24
触发器问题 当表a中插入一条数据时。把插入的数据存入b表中 怎么写呀????求帮助
最佳答案
- 五星知识达人网友:等灯
- 2021-02-27 02:58
交给我吧,这是个最基础的触发器,假设A表的2个字段为ID,name,B表与A表字段相同
create or replace trigger AB_DML_TGR
after insert
on A
for each row
begin
if inserting then
insert into B
values
(:new.ID,
:new.name);
DBMS_OUTPUT.PUT_LINE('新数据已保存到B中');
end if;
end;追问create trigger MyDocFileTrg
on WCMAPPENDIX
for insert,update
as
declare @FILENAME nvarchar(255),
@CRUSER nvarchar(50)
begin
select @FILENAME=APPFILE,@CRUSER=CRUSER from inserted
INSERT INTO XWCMMyDocFileTrg (APPFILE,CRUSER) VALUES (@FILENAME,@CRUSER)
end
我也搞定了
create or replace trigger AB_DML_TGR
after insert
on A
for each row
begin
if inserting then
insert into B
values
(:new.ID,
:new.name);
DBMS_OUTPUT.PUT_LINE('新数据已保存到B中');
end if;
end;追问create trigger MyDocFileTrg
on WCMAPPENDIX
for insert,update
as
declare @FILENAME nvarchar(255),
@CRUSER nvarchar(50)
begin
select @FILENAME=APPFILE,@CRUSER=CRUSER from inserted
INSERT INTO XWCMMyDocFileTrg (APPFILE,CRUSER) VALUES (@FILENAME,@CRUSER)
end
我也搞定了
全部回答
- 1楼网友:woshuo
- 2021-02-27 05:40
ORACLE正解
- 2楼网友:孤独的牧羊人
- 2021-02-27 04:14
帮忙看一下这个触发器,要求:当cl_bm中添加一条记录,同时在zd_yz语句中写一条记录,下面触发器没生效
CREATE TRIGGER TR_CLBM_CR
ON CL_BM
FOR INSERT
AS
INSERT
ZD_YZ(LX, BM, DH, MC, DJ, JL, YLDW, JLDW, GG, FYLB, CLLB, STATE, ZXBZ, GBBM, PRINTMC)
SELECt top 1
1, BM, DH, MC, DJ, 1, DW, DW, GG, FYLB = 71, CLLB=0, STATE = 0, ZXBZ = 0 , GBBM, PRINTMC=MC
FROM CL_BM where lb like '2%' and bm not in (select bm from inserted)
CREATE TRIGGER TR_CLBM_CR
ON CL_BM
FOR INSERT
AS
INSERT
ZD_YZ(LX, BM, DH, MC, DJ, JL, YLDW, JLDW, GG, FYLB, CLLB, STATE, ZXBZ, GBBM, PRINTMC)
SELECt top 1
1, BM, DH, MC, DJ, 1, DW, DW, GG, FYLB = 71, CLLB=0, STATE = 0, ZXBZ = 0 , GBBM, PRINTMC=MC
FROM CL_BM where lb like '2%' and bm not in (select bm from inserted)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯