码迷,mamicode.com
首页 > 数据库 > 详细

db2触发器例子

时间:2014-06-18 12:35:39      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:db2触发器例子

-- 建表语句
CREATE TABLE WANGZSTABLE (
  ID	INTEGER	NOT NULL,
  NAME	VARCHAR(20)	NOT NULL,
  AGE	VARCHAR(20)	NOT NULL,
  STATUS	VARCHAR(10),
  CREATETIME	TIMESTAMP,
  UPDATETIME	TIMESTAMP,
  SENDTIME	TIMESTAMP
);

select * from wangzsTable;
insert into WANGZSTABLE(id,name,age) values(1,'wangzs1','26');
update WANGZSTABLE set status='2' where id=1;


--update 更新特定状态 status=4
DROP TRIGGER "WANGZS_UPDATE";

CREATE TRIGGER WANGZS_UPDATE
  AFTER UPDATE OF STATUS ON WANGZSTABLE
  REFERENCING OLD AS OLDROW NEW AS NEWROW
  FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
  IF(NEWROW.STATUS='4')
    THEN
      update wangzsTable set UPDATETIME=CURRENT TIMESTAMP where id=NEWROW.id;
  END IF;
END;

--update 更新特定id
DROP TRIGGER "WANGZS_UPDATE";

CREATE TRIGGER WANGZS_UPDATE
  AFTER UPDATE OF STATUS ON WANGZSTABLE
  REFERENCING OLD AS OLDROW NEW AS NEWROW
  FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
    update wangzsTable set UPDATETIME=CURRENT TIMESTAMP where id=NEWROW.id;
END;

--insert
DROP TRIGGER "WANGZS_INSERT";

CREATE TRIGGER WANGZS_INSERT
  AFTER INSERT ON WANGZSTABLE
  REFERENCING  NEW AS NEWROW
  FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
    update wangzsTable set CREATETIME=CURRENT TIMESTAMP where id=NEWROW.id;
END;


db2触发器例子,布布扣,bubuko.com

db2触发器例子

标签:db2触发器例子

原文地址:http://blog.csdn.net/adam_wzs/article/details/31419671

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!