在oracle里使用自增ID字段的步骤比较繁琐,总结如下:
— 创建表
CREATE TABLE ADVICE
(
ID INT NOT NULL,
ACTIVE INT DEFAULT 1 NOT NULL,
TYPE INT NOT NULL,
MSG VARCHAR2(512) NOT NULL,
ADVICE VARCHAR2(4000) NOT NULL,
PRIMARY KEY(ID),
CONSTRAINT ADVICE_UNI UNIQUE(TYPE,MSG)
)TABLESP
DB2 代码如下:CREATE TABLE T1( id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE 1 NO MAXVALUE NO CYCLE NO CACHE ORDER ), …); Oracle(需要创建一个SEQUENCE和一个TRIGGER): 代码如下:CREATE TABLE T1( id NUM
相关代码如下: 1. 创建sequence: 代码如下:CREATE SEQUENCE SEQU_DATA_DATAINFO INCREMENT BY 1 START WITH 1 NOCYCLE NOCACHE NOORDER; 2. 创建触发器: 代码如下:create or replace TRIGGER TRIG_TEST BEFORE INSERT ON TABLE1 FOR EACH ROW DECLARE tmpVar NUMBER; BEGIN tmpVar := 0; Se