Add a varchar column to the table:
Alter table distributors add column address varchar (30 );
Delete a field from the table:
Alter table distributors drop column address restrict;
Modify the types of two existing fields in one operation:
Alter table distributors
Alter column address type varchar (80 ),
Alter column name type varchar (100 );
Use a using clause to convert an integer field containing UNIX timestamps to timestamp with time zone:
Alter table foo
Alter column foo_timestamp type Timestamp with Time Zone
Using
Timestamp with Time Zone 'epoch' + foo_timestamp * interval '1 second ';
Rename existing fields:
Alter table distributors rename column address to city;
Change the name of an existing table:
Alter table distributors Rename to suppliers;
Add a non-empty constraint to a field:
Alter table distributors alter column street set not null;
Delete A non-empty constraint from a field:
Alter table distributors alter column Street Drop not null;
Add a check constraint to a table:
Alter table distributors add constraint zipchk check (char_length (zipcode) = 5 );
To delete a table and all its sub-tables, follow these constraints:
Alter table distributors drop constraint zipchk;
Add a foreign key constraint to the table:
Alter table distributors add constraint distfk foreign key (Address) References addresses (Address) match full;
Add a unique (Multi-field) constraint to the table:
Alter table distributors add constraint dist_id_zipcode_key unique (dist_id, zipcode );
Add an automatically named primary key constraint to a table. Note that a table can only have one primary key:
Alter table distributors add primary key (dist_id );
Move the table to another tablespace:
Alter table distributors set tablespace fasttablespace;