This section is from the "Practical PostgreSQL" book, by John Worsley and Joshua Drake. Also available from Amazon: Practical PostgreSQL.
The various forms of syntax for ALTER TABLE are summarized in Table 4-3 , and described in detail in the following sections.
Table 4-3. ALTER TABLE Syntax
Element | Description |
|---|---|
ALTER TABLE table_name
ADD [ COLUMN ]
column_name column_type
| Adds a column named column_name of type column_type to the table called table_name . |
ALTER TABLE table_name
ALTER [ COLUMN ]
column_name
{ SET DEFAULT value |
DROP DEFAULT }
| Either sets the default value of value to the column column_name of the table called table_name , or removes an existing default value. |
ALTER TABLE table_name
RENAME TO new_table_name
| Renames the table called table_name to new_table_name . |
ALTER TABLE table_name
RENAME [ COLUMN ]
column_name
TO new_column_name
| Renames the column column_name within the table called table_name to new_column_name . |
ALTER TABLE table_name
ADD CONSTRAINT
constraint_name
constraint_definition
| Adds a constraint named constraint_name with the definition of constraint_definition to the table called table_name . |
ALTER TABLE table_name
OWNER TO new_owner
| Changes the ownership of the table called table_name to the user new_owner . |
 
Continue to: