oracle 触发器的更新两张数据表
时间:2011-12-05
来源:互联网
我想通过插入一张表的信息时候更新另一张表,该怎么弄呢,求教,如下数据:
drop table t_info;
create table t_info(
infoid number(3) primary key,
infoname char(20),
static char(20));
drop table t_lent;
create table t_lent(
lentid number(3) primary key,
infoid number(3),
lentname char(20) not null
);
insert into t_info values(1,'洗衣机','可用');
insert into t_info values(2,'电冰箱','可用');
create trigger lenttoinfo
after insert on t_lent for
each row
begin
update t_info
set static:='已使用' where infoid = old.infoid;
end;
insert into t_lent values(1,1,'洗衣服');
请问为什么我的触发器不正确呢,怎么写才正确呢。
我想要的结果插t_lent表时候,t_info表标记已使用。
drop table t_info;
create table t_info(
infoid number(3) primary key,
infoname char(20),
static char(20));
drop table t_lent;
create table t_lent(
lentid number(3) primary key,
infoid number(3),
lentname char(20) not null
);
insert into t_info values(1,'洗衣机','可用');
insert into t_info values(2,'电冰箱','可用');
create trigger lenttoinfo
after insert on t_lent for
each row
begin
update t_info
set static:='已使用' where infoid = old.infoid;
end;
insert into t_lent values(1,1,'洗衣服');
请问为什么我的触发器不正确呢,怎么写才正确呢。
我想要的结果插t_lent表时候,t_info表标记已使用。
作者: jake512 发布时间: 2011-12-05
没弄懂你的意思。是要在插入t_lent表的时候同时更新t_info表吗?如果是,代码如下
create trigger lenttoinfo
after insert on t_lent for
each row
begin
update t_info
set static='已使用' where infoid = old.infoid;
end;
create trigger lenttoinfo
after insert on t_lent for
each row
begin
update t_info
set static='已使用' where infoid = old.infoid;
end;
作者: nvhaixx 发布时间: 2011-12-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28