首页 > 数据库技术 > 详细

postgresql 表结构变更相关操作

时间:2020-06-18 21:39:40      阅读:58      评论:0      收藏:0      [点我收藏+]

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 表结构变更相关操作

原文:https://www.cnblogs.com/yb38156/p/10063673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!