(1) MySQL auto_increment
ID int auto_increment primary key not null
(2)MS SQL Server identity
ID int identity(1,1) primary key not null
(3)Oracle Sequence
create sequence CUSTOMERS_ID_SEQ increment by 2 start with 1
curval 返回序列的当前值。
nextval 先增加序列的值,然后返回序列值。
create table CUSTOMERS(ID int primary key not null,.....)
insert into CUSTOMERS values(CUSTOMERS_ID_SEQ.curval,'Tom',.....)
ID int auto_increment primary key not null
(2)MS SQL Server identity
ID int identity(1,1) primary key not null
(3)Oracle Sequence
create sequence CUSTOMERS_ID_SEQ increment by 2 start with 1
curval 返回序列的当前值。
nextval 先增加序列的值,然后返回序列值。
create table CUSTOMERS(ID int primary key not null,.....)
insert into CUSTOMERS values(CUSTOMERS_ID_SEQ.curval,'Tom',.....)
本文介绍了在MySQL、MSSQL Server及Oracle三种数据库中实现自增ID的方法。MySQL使用auto_increment属性,MSSQL Server采用identity属性,而Oracle则通过创建序列实现自增,并提供了curval和nextval两个函数来获取序列值。
952

被折叠的 条评论
为什么被折叠?



