Oracle中建表,序列,触发器

-- Create table TMotifPromotion
create table TMotifPromotion
(
  MotifPromotionSN        NUMBER(16) not null,
  MotifPromotionCode      nvarchar2(10),
  MotifPromotionName      nvarchar2(50),
  StartDate               DATE,
  EndDate                 Date,
  Remark                  NVARCHAR2(300),
  Flag                    nchar(1),           ----*注销,1有效
  CreatedBy               Number(8),
  CreatedOn               Date,
  LastUpdatedBy           Number(8),
  LastUpdatedOn           Date
)


-- Create sequence TMotifPromotion_MotifPromotionSN
create sequence TMotifPromotion_MPSN
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;

 

--  Create trigger TI_TMotifPromotion
CREATE  TRIGGER TI_TMotifPromotion BEFORE
INSERT ON TMotifPromotion REFERENCING OLD AS old_value NEW AS
    new_value
    FOR EACH ROW
 
when (new_value.MotifPromotionSN is null)
BEGIN
 select TMotifPromotion_MPSN.nextval into :new_value.MotifPromotionSN from dual;
END;

posted on 2009-04-17 16:45  jameshappy  阅读(580)  评论(0编辑  收藏  举报