Postgresql ALTER语句常用操作小结

前端之家收集整理的这篇文章主要介绍了Postgresql ALTER语句常用操作小结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

postgresql版本:psql (9.3.4)

1、增加一列


ALTER TABLE table_name ADD column_name datatype;             


2、删除一列


ALTER TABLE table_name DROP  column_name;                             


3、更改列的数据类型


ALTER TABLE table_name ALTER  column_name TYPE datatype;              


4、表的重命名


ALTER TABLE table_name RENAME TO new_name;                           


5、更改列的名字


ALTER TABLE table_name RENAME column_name to new_column_name;          


6、字段的not null设置


ALTER TABLE table_name ALTER column_name {SET|DROP} NOT NULL;          


7、给列添加default


ALTER TABLE table_name ALTER column_name SET DEFAULT expression;  
ALTER TABLE "crm_customer_call" alter COLUMN "tenant_id" DROP DEFAULT;
ALTER TABLE "crm_customer_call"
ADD CONSTRAINT MyUniqueConstraint UNIQUE(cti_call_id);

猜你在找的Postgre SQL相关文章