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 do I use PostgreSQL's XMIN and XMAX features?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I monitor PostgreSQL performance using Zabbix?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I parse XML data using PostgreSQL?
- How do I use PostgreSQL variables in my software development project?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL with Zabbix?
See more codes...