The Postgresql ALTER statement is commonly used for operation summaries

  • 2020-05-06 11:52:22
  • OfStack

postgresql version: psql (9.3.4)

Add a column


ALTER TABLE table_name ADD column_name datatype;            

2, delete a column

ALTER TABLE table_name DROP  column_name;                            

3. Change the data type of the column

ALTER TABLE table_name ALTER  column_name TYPE datatype;             

4, rename
of the table

ALTER TABLE table_name RENAME TO new_name;                          

5. Change the name of the column

ALTER TABLE table_name RENAME column_name to new_column_name;         

6. not null of the field is set to

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

7. Add default
to the column

ALTER TABLE table_name ALTER column_name SET DEFAULT expression; 


Related articles: