首页 > 代码库 > oracle创建表(并且实现ID自增)

oracle创建表(并且实现ID自增)

CREATE TABLE STUDENT(ID INT NOT NULL,NAME VARCHAR2(4000) NOT NULL,PRIMARY KEY(ID))TABLESPACE MYDB; --创建自增ID,名称为:表名_字段名_SEQCREATE SEQUENCE sTUDENT_ID_SEQ MINVALUE 1 NOMAXVALUE INCREMENT BY 1 START WITH 1 NOCACHE;  -- 为Insert操作创建触发器,无需在SQL语句里写NEXTVAL,名称为表名_INS_TRGCREATE OR REPLACE TRIGGER sTUDENT_INS_TRG BEFORE INSERT ON STUDENT FOR EACH ROW WHEN(NEW.ID IS NULL)BEGINSELECT STUDENT_ID_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;END;

 

oracle创建表(并且实现ID自增)