postgresql 表结构变更相关操作

Posted 鼠标的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgresql 表结构变更相关操作相关的知识,希望对你有一定的参考价值。

1、列操作

新增一列:alter table [tbl_name] add column [column_name] [type]

删除一列:alter table [tbl_name] drop [column_name];

修改列名:alter table [tbl_name] rename [column_name] to [column_name_1]; 

修改列类型:alter table [tbl_name] alter COLUMN [column_name] type varchar(255)

2、序列操作

重置序列:alter sequence xxx restart with 1

创建序列:create sequence xxx START with 1 INCREMENT by 1 NO MINVALUE NO MAXVALUE CACHE 1

给某一列赋上序列:alter table [tbl_name] alter column [column_name] set default nextval(xxx)

3、设置主键

alter table [tbl_name] add constraint pkey_name ;

 

以上是关于postgresql 表结构变更相关操作的主要内容,如果未能解决你的问题,请参考以下文章