PostgreSQL
PostgreSQL DROP COLUMN
Remove an unwanted column from an existing PostgreSQL table with ALTER TABLE.
The ALTER TABLE statement
To remove a column from a table, use the ALTER TABLE statement. It
can also be used to add or modify columns and to add or drop constraints on an
existing table.
DROP COLUMN
We will remove the column named color from the
products table. Use DROP COLUMN to remove the column
and the data stored in it:
Remove the color column with this statement:
ALTER TABLE products
DROP COLUMN color;
Result
PostgreSQL reports:
ALTER TABLE
This confirms that the table structure was changed successfully.
Display the table
To check the result, display the table with this statement:
SELECT * FROM products;
The color column is no longer included in the result. Dropping a
column also removes all data stored in that column, so confirm the column is no
longer needed before executing the statement.
DROP COLUMN IF EXISTS color when you want to
avoid an error if the column has already been removed.
Further Reading
Continue learning with these related tutorials:
- PostgreSQL Introduction
- PostgreSQL pgAdmin 4
- PostgreSQL Create Table
- PostgreSQL Insert Data
- PostgreSQL Select Data
- PostgreSQL ADD COLUMN
- PostgreSQL UPDATE
- PostgreSQL ALTER COLUMN
- PostgreSQL DROP COLUMN
- PostgreSQL DELETE
- PostgreSQL DROP TABLE
- PostgreSQL Operators
- PostgreSQL SELECT
- PostgreSQL SELECT DISTINCT
- PostgreSQL WHERE
- PostgreSQL ORDER BY
- PostgreSQL LIMIT
- PostgreSQL MIN and MAX
- PostgreSQL COUNT
- PostgreSQL SUM
- PostgreSQL AVG
- PostgreSQL LIKE
- PostgreSQL IN
- PostgreSQL BETWEEN
- PostgreSQL AS
- PostgreSQL Joins
- PostgreSQL INNER JOIN
- PostgreSQL LEFT JOIN
- PostgreSQL RIGHT JOIN
- PostgreSQL FULL JOIN
- PostgreSQL CROSS JOIN
- PostgreSQL UNION
- PostgreSQL GROUP BY
- PostgreSQL HAVING
- PostgreSQL EXISTS
- PostgreSQL ANY
- PostgreSQL ALL
- PostgreSQL CASE
Continue learning
