zoukankan      html  css  js  c++  java
  • postgreSQL 自增需要使用序列

    postgreSQL 自增需要使用序列

    1.使用SERIAL

    CREATE TABLE users  
    (  
    id SERIAL4 primary key ,  
    name character varying,  
    password character varying  
    )  

    自动创建名为users_id_seq的序列,其起始值为1,步增为1,且MAXVALUE=2147483647, 其中serial4 创建后对应 int4, 如果是serial2 则对应为int2。实际和方法2的效果是一样的,并且不用手动创建序列。只是以前的版本可能是serial,一开始执行失败,现在发现是这一个样子的。

    2.先创建序列,然后设置字段的自增

    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');  

    我是采用第二种方法成功的。

  • 相关阅读:
    PRCT-1302 the OCR has an invalid ip address
    函数listen
    函数bind
    函数socket
    lamp。查看版本
    yii 日期插件
    UCenter 的目录结构
    API接口
    返回标签数据示例 (PHP)
    应用接口函数
  • 原文地址:https://www.cnblogs.com/wayne173/p/8679029.html
Copyright © 2011-2022 走看看