当前位置: 数据库>oracle
浅析常用数据库的自增字段创建方法汇总
来源: 互联网 发布时间:2014-09-07
本文导语: 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): 代码如下:CRE...
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 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,
...
);
PostgreSQL
CREATE TABLE T1
(
id SERIAL NOT NULL,
...
);
SQL Server
CREATE TABLE T1
(
id INT NOT NULL IDENTITY,
...
);
Sybase
CREATE TABLE T1
(
id INT NOT NULL IDENTITY,
...
);
代码如下:
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 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,
...
);
PostgreSQL
代码如下:
CREATE TABLE T1
(
id SERIAL NOT NULL,
...
);
SQL Server
代码如下:
CREATE TABLE T1
(
id INT NOT NULL IDENTITY,
...
);
Sybase
代码如下:
CREATE TABLE T1
(
id INT NOT NULL IDENTITY,
...
);
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。