Postgresql ALTER語句常用操作小結,postgresqlalter

來源:互聯網
上載者:User

Postgresql ALTER語句常用操作小結,postgresqlalter

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; 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.