浅析常用数据库的自增字段创建方法汇总
Jun 07, 2016 pm 04:19 PM本篇文章是对常用数据库的自增字段创建方法进行了全面的汇总介绍,需要的朋友参考下 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
本篇文章是对常用数据库的自增字段创建方法进行了全面的汇总介绍,,需要的朋友参考下
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,
...
);

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts)

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs)

How to set font size on mobile phone (easily adjust font size on mobile phone)

The difference between Go language methods and functions and analysis of application scenarios

How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors)

Detailed tutorial on establishing a database connection using MySQLi in PHP

How does Hibernate implement polymorphic mapping?

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos
