DatabaseLesson 9Free preview
PostgreSQL ADD COLUMN
This lesson is part of PostgreSQL · All levels
Summary
When the structure of the table needs to evolve, the alter table... ADD Columns are used to add new columns to an existing table. You can instantly specify the data type, constraint, or default value. In tables that already contain data, the addition of the NOT NULL column is generally accompanied by a DEFAULT to keep the old line valid.
Key points
- ALTER TABLE name_table ADD column name_column type; add a new column.
- Giving a default makes the long line directly loaded with the default value.
- Adding the NOT column to the table containing the data needs to be accompanied by the DEFAULT.
- Constraints like UNIQUE can be defined directly when you add a column.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.