Home Database Mysql Tutorial 浅析常用数据库的自增字段创建方法汇总

浅析常用数据库的自增字段创建方法汇总

Jun 07, 2016 pm 04:19 PM
create Field Commonly used database method Summary self-increasing

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

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) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

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) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

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 The difference between Go language methods and functions and analysis of application scenarios Apr 04, 2024 am 09:24 AM

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) 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) May 07, 2024 pm 05:55 PM

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 Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

How does Hibernate implement polymorphic mapping?

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

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

See all articles