Auto-increment key

MySQL auto-increment primary key

  • Different ways to define automatic incremental primary key

-- MySQL
create table β€˜test’ (
  β€˜id’  int(16) NOT NULL AUTO_INCREMENT,
  β€˜name’  char(10) DEFAULT NULL,
  PRIMARY KEY(β€˜id’) 
) ENGINE = InnoDB;

-- Oracle create sequence
create sequence test_seq increment by 1 start with 1;
insert into test(id, name) values(test_seq.nextval, ' An example ');

Cons

  • Not unique in distributed environments.

Last updated