shisgmei 发表于 2016-11-22 00:19:42

postgresql 设置字段的自动增长

  以前使用mysql 设置自动增长的语句如下
  create table person(id int not null primary key auto_increment);
  mysql是用auto_increment这个属性来标识字段的自增,在使用insert 语句时候id 这个字段的值可以写 ''或NULL
  postgresql 使用序列来标识字段的自增长
  CREATE TABLE daodaoimg
(
id serial NOT NULL,
alttext text,
imgurl text
)
  直行这条语句后 会自动生成daodaoimg_id_seq这个序列
  insert 语句的时候可以不加id这个字段   insert into daodaoimg(alttext,imgurl) values('','');
页: [1]
查看完整版本: postgresql 设置字段的自动增长