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 can I create a hierarchical query in PostgreSQL?
- How can I set a PostgreSQL interval to zero?
- How do I create a PostgreSQL function?
- How can I use PostgreSQL's "zero if null" feature?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I write a PostgreSQL query to retrieve JSON data?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL with YAML?
- How can I retrieve data from PostgreSQL for yesterday's date?
See more codes...