PostgreSQL触发器怪事.??????

9812 2003-03-19 10:54:56
PostgreSQL触发器怪事.??????

drop table taba;
create table taba(
id integer,
name varchar(50)
);
insert into taba values(1,'chen');
insert into taba values(2,'chen');
insert into taba values(3,'chen');
insert into taba values(4,'chen');
insert into taba values(5,'chen');
insert into taba values(6,'chen');
insert into taba values(7,'chen');
select * from taba;


drop table tabb;
create table tabb(
id integer,
name varchar(50)
);
insert into tabb values(1,'chen');
insert into tabb values(2,'chen');
insert into tabb values(3,'chen');
insert into tabb values(4,'chen');
insert into tabb values(5,'chen');
insert into tabb values(6,'chen');
insert into tabb values(7,'chen');
select * from tabb;

drop function delete_tab ();
CREATE FUNCTION delete_tab () RETURNS opaque AS '
-- DECLARE
BEGIN
Delete from tabb where id = OLD.id;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

drop TRIGGER delete_tri on taba;
CREATE TRIGGER delete_tri
AFTER Delete
ON taba FOR EACH ROW
EXECUTE PROCEDURE delete_tab ();

删除表taba中的数据.tabb中的id=2也被删除.
delete from taba where id = 2;
select * from taba;
select * from tabb;

因我要用外建..所得改上面程序如下
CREATE TRIGGER delete_tri
before Delete
ON taba FOR EACH ROW
EXECUTE PROCEDURE delete_tab ();

before Delete 后...不知为什么.
delete from taba where id = 2;
select * from taba;
select * from tabb;
tabb中的数据被删除,但taba中的数据没有动.记录还在.????????
急...谢谢
...全文
22 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
tttt415 2003-03-22
trigger修改为before delete后,对应的function也需要修改,原来返回NEW,现在就需要返回old.
回复
相关推荐
发帖
MySQL
创建于2007-09-28

5.5w+

社区成员

MySQL相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-03-19 10:54
社区公告
暂无公告