postgresql_16:3.2.6 Modifying Tables
PostgreSQL 16 > The SQL Language > Data Definition > Modifying Tables
When you create a table and you realize that you made a mistake, or the requirements of the application change, you can drop the table and create it again. But this is not a convenient option if the table is already filled with data, or if the table is referenced by other database objects (for instance a foreign key constraint). Therefore PostgreSQL provides a family of commands to make modifications to existing tables. Note that this is conceptually distinct from altering the data contained in the table: here we are interested in altering the definition, or structure, of the table.
You can: Add columns Remove columns Add constraints Remove constraints Change default values Change column data types Rename columns Rename tables All these actions are performed using the (see postgresql_16:7.1.33) command, whose reference page contains details beyond those given here.
Subsections
- postgresql_16:3.2.6.1 Adding a Column
- postgresql_16:3.2.6.2 Removing a Column
- postgresql_16:3.2.6.3 Adding a Constraint
- postgresql_16:3.2.6.4 Removing a Constraint
- postgresql_16:3.2.6.5 Changing a Column's Default Value
- postgresql_16:3.2.6.6 Changing a Column's Data Type
- postgresql_16:3.2.6.7 Renaming a Column
- postgresql_16:3.2.6.8 Renaming a Table