不同数据库自增字段的创建实现举例

1、MySQL: create table tableName(id int auto_increment,name varchar(20),primary key(id));
      alter table tableName auto_increment=1;


2、SQLServer: CREATE TABLE tableName (id int identity(1,1), name varchar(10));


3、Oracle: 创建序列,通过序列实现。
  创建序列:create sequence autoID increment by 1 start with 1 maxvalue 999999 cycle;
  插入数据:insert into tablename values(autoID.nextval,...);

  或者通过在序列的基础上创建触发器
  create or replace trigger tableName_trigger
    before insert on tableName
    for each row
    begin
      select autoID.nextval into :new.id from dual;
    end ;
  插入数据:insert into tablename (name) values('');

原文地址:https://www.cnblogs.com/moleme/p/4936419.html