使用DDL语句创建主键自增的Oracle数据库表结构:
CREATE TABLE "SCOTT"."ADMINS" (
"ID" NUMBER(10) NOT NULL ,
"MERID" VARCHAR2(200 CHAR) NULL ,
"SUBID" VARCHAR2(200 CHAR) NULL ,
"SUBNAME" VARCHAR2(200 CHAR) NULL ,
"STATUS" VARCHAR2(200 CHAR) NULL ,
"REMARK" VARCHAR2(200 CHAR) NULL
)
LOGGING
NOCOMPRESS
NOCACHE
;
--创建自增ID,名称为:表名_字段名_SEQ
CREATE SEQUENCE ADMINS_ID_SEQ MINVALUE 1 NOMAXVALUE INCREMENT BY 1 START WITH 1 NOCACHE;
-- 为Insert操作创建触发器,无需在SQL语句里写NEXTVAL,名称为表名_INS_TRG
CREATE OR REPLACE TRIGGER ADMINS_INS_TRG BEFORE INSERT ON ADMINS FOR EACH ROW WHEN(NEW.ID IS NULL)
BEGIN
SELECT ADMINS_ID_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
END;