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 the PostgreSQL hash function?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I set a PostgreSQL interval to zero?
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I extract the year from a PostgreSQL timestamp?
- How can I extract the year from a date in PostgreSQL?
- How can I retrieve data from PostgreSQL for yesterday's date?
See more codes...