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 ),
...
);
(
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 NUMBER(10,0) NOT NULL,
...
);
CREATE SEQUENCE T1_ID_SEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE CACHE 100 ORDER;
CREATE OR REPLACE TRIGGER INSERT_T1_ID
BEFORE INSERT ON T1
REFERENCING NEW AS new OLD AS old
FOR EACH ROW
BEGIN
SELECT T1_ID_SEQ.NEXTVAL INTO :new.id FROM DUAL;
END;
(
id NUMBER(10,0) NOT NULL,
...
);
CREATE SEQUENCE T1_ID_SEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE CACHE 100 ORDER;
CREATE OR REPLACE TRIGGER INSERT_T1_ID
BEFORE INSERT ON T1
REFERENCING NEW AS new OLD AS old
FOR EACH ROW
BEGIN
SELECT T1_ID_SEQ.NEXTVAL INTO :new.id FROM DUAL;
END;
MysqL
代码如下:
CREATE TABLE T1
(
id INT NOT NULL AUTO_INCREMENT,
...
);
(
id INT NOT NULL AUTO_INCREMENT,
...
);
Postgresql
代码如下:
CREATE TABLE T1
(
id SERIAL NOT NULL,
...
);
(
id SERIAL NOT NULL,
...
);
sql Server
代码如下:
CREATE TABLE T1
(
id INT NOT NULL IDENTITY,
...
);
(
id INT NOT NULL IDENTITY,
...
);
Sybase
代码如下:
CREATE TABLE T1
(
id INT NOT NULL IDENTITY,
...
);
原文链接:https://www.f2er.com/oracle/65498.html(
id INT NOT NULL IDENTITY,
...
);