ITeye博客

PostgreSQL主键自增方法

Horse_Chasing · 2016-03-31 00:19 · 数据库 · 数据库 · Markdown

PG主键自增,方式跟oracle类似 1、首先创建序列 CREATE SEQUENCE test_c_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;

2、如果表已经存在了,则执行下面语句: alter table test_c alter column id set default nextval('test_c_id_seq');

3、如果表不存在,则: create table table_name( id int not null primary key default nextval('id_seq'), name varchar(30)

)

所有博客已经转移至leanote:http://blog.leanote.com/shiwei/

或者:http://luoshiwei.me/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。