PostgreSQL 设置字段自增

Posted by wxianfeng Thu, 10 Apr 2014 07:30:00 GMT

利用序列可以实现字段的自增。

pgAdmin 入口:
pgAdmin → Tools → Query Tool

CREATE SEQUENCE users_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;



alter table users alter column id set default nextval(users_id_seq);

查看表的创建脚本可以看到使用的序列:
pgAdmin → Object → SCRIPTS → Create Script

This entry was posted on Thu, 10 Apr 2014 07:30:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags


Trackbacks

Use the following link to trackback from your own site:
http://blog.wxianfeng.com/trackbacks?article_id=324

Comments

  1. Avatar
    buddypress.org about {{count}} years ago:

    Hi there, this weekend is nice designed for me, because
    this point in time i am reading this impressive educational post here at my
    residence.

  2. Avatar
    buddypress.org about {{count}} years ago:

    Hi there, this weekend is nice designed for me, because this point in time
    i am reading this impressive educational post here at my residence.

Leave a comment