postgresqlHow do I use the ALTER TABLE command in PostgreSQL?
The ALTER TABLE command in PostgreSQL is used to modify existing tables in the database. It can be used to add, modify, or delete columns, change the data type of columns, add or remove constraints, and rename tables.
Example code
ALTER TABLE orders
ADD COLUMN order_date date;
This example code adds a new column called 'order_date' to the 'orders' table with a data type of 'date'.
The parts of the code are:
- ALTER TABLE: This is the command used to modify existing tables.
- orders: This is the name of the table to be modified.
- ADD COLUMN: This is the action being taken on the table.
- order_date: This is the name of the new column being added.
- date: This is the data type of the new column being added.
Helpful links
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I use PostgreSQL UNION to combine the results of two queries?
- How do I decide whether to use PostgreSQL VARCHAR or TEXT data types?
- How do I use PostgreSQL with Qt?
- How can I retrieve data from PostgreSQL for yesterday's date?
See more codes...