db2觸發器例子

來源:互聯網
上載者:User

-- 建表語句CREATE TABLE WANGZSTABLE (  IDINTEGERNOT NULL,  NAMEVARCHAR(20)NOT NULL,  AGEVARCHAR(20)NOT NULL,  STATUSVARCHAR(10),  CREATETIMETIMESTAMP,  UPDATETIMETIMESTAMP,  SENDTIMETIMESTAMP);select * from wangzsTable;insert into WANGZSTABLE(id,name,age) values(1,'wangzs1','26');update WANGZSTABLE set status='2' where id=1;--update 更新特定狀態 status=4DROP TRIGGER "WANGZS_UPDATE";CREATE TRIGGER WANGZS_UPDATE  AFTER UPDATE OF STATUS ON WANGZSTABLE  REFERENCING OLD AS OLDROW NEW AS NEWROW  FOR EACH ROW MODE DB2SQLBEGIN ATOMIC  IF(NEWROW.STATUS='4')    THEN      update wangzsTable set UPDATETIME=CURRENT TIMESTAMP where id=NEWROW.id;  END IF;END;--update 更新特定idDROP TRIGGER "WANGZS_UPDATE";CREATE TRIGGER WANGZS_UPDATE  AFTER UPDATE OF STATUS ON WANGZSTABLE  REFERENCING OLD AS OLDROW NEW AS NEWROW  FOR EACH ROW MODE DB2SQLBEGIN ATOMIC    update wangzsTable set UPDATETIME=CURRENT TIMESTAMP where id=NEWROW.id;END;--insertDROP TRIGGER "WANGZS_INSERT";CREATE TRIGGER WANGZS_INSERT  AFTER INSERT ON WANGZSTABLE  REFERENCING  NEW AS NEWROW  FOR EACH ROW MODE DB2SQLBEGIN ATOMIC    update wangzsTable set CREATETIME=CURRENT TIMESTAMP where id=NEWROW.id;END;

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.