欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PostgreSQL MySQL 兼容性之 - 自增值

程序员文章站 2022-07-13 10:30:48
...

AUTO_INCREMENT , sequence

MySQL

  AUTO_INCREMENT 
    The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows. 
    When you insert a new record to the table, and the auto_increment field is NULL or DEFAULT, the value will automatically be incremented. 
    This also applies to 0, unless the NO_AUTO_VALUE_ON_ZERO SQL_MODE is enabled.

PostgreSQL

  serial4
  create table test(id serial4);
    or
  serial8
  create table test(id serial8);
    or
  create sequence seq;
  create table test(id int default nextval('seq'::regclass));