一 创建表结构:
DROP TABLE base_list;
CREATE TABLE base_list (
“DATA_LIST_ID” NUMBER NOT NULL ,
“BASE_DATA_ID” NUMBER NOT NULL ,
“BASE_DATA_LIST” VARCHAR2(100 BYTE) NOT NULL ,
“FLAG” NUMBER DEFAULT 0 NOT NULL
)
LOGGING
NOCOMPRESS
NOCACHE
二 创建序列:
CREATE SEQUENCE SEQ_DATA_LIST_ID– SEQ_DATA_LIST_ID 自动增长列
INCREMENT BY 1 – 每次加几个
START WITH 1 – 从1开始计数
NOMAXVALUE – 不设置最大值
NOCYCLE – 一直累加,不循环
NOCACHE
三 创建触发器:
CREATE OR REPLACE TRIGGER “BSQAM1”.”T_DATA_LIST_ID” BEFORE INSERT ON “BSQAM1”.”BASE_LIST” REFERENCING OLD AS “OLD” NEW AS “NEW” FOR EACH ROW
begin
—在新增之前将自增的主键字段的值赋值为sequence的nextval
select SEQ_DATA_LIST_ID.nextval INTO :NEW.DATA_LIST_ID from dual;
end;
四 创建外键:
–使用alter table创建外键
alter table CERTIFICATE
add constraint F_USER_ID
foreign key (USER_ID)
references TUSER(USER_ID);