ALTER TABLE — Concept Check
Questions on ALTER TABLE. ALTER TABLE modifies an existing table's structure — adding, dropping, or modifying columns, and adding or dropping constraints without recreating the table.
Questions in this quiz
8 questions on ALTER TABLE — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A PostgreSQL database is running version 11. You add a NOT NULL column with a constant default. What happens?
- AThe column is added instantly, no rewrite.
- BThe operation fails due to constraints.
- CThe table is locked but not rewritten.
- DThe table is rewritten, locking it.
2.You need to change a column's data type in PostgreSQL. What should you be cautious about?
- AIt requires dropping and recreating the table.
- BIt can be done without any downtime.
- CIt may require a CAST and lock the table.
- DIt will always be instant with no locks.
3.In MySQL, which statement is used to change a column's data type?
- AALTER COLUMN
- BMODIFY COLUMN
- CCHANGE CONSTRAINT
- DADD COLUMN
4.You add a nullable column to a large PostgreSQL table. What is the impact?
- AThe column is added instantly, no locks.
- BThe table is locked but not rewritten.
- CThe table is rewritten, causing locks.
- DThe operation fails due to size constraints.
5.What is a critical step in zero-downtime migrations for large tables?
- ADropping the old column first.
- BBackfilling in batches.
- CSkipping validation of constraints.
- DAdding NOT NULL immediately.
6.Which operation in PostgreSQL requires a full table lock?
- AChanging data type.
- BDropping a column.
- CAdding a nullable column.
- DRenaming a column.
7.Why use tools like Flyway or Liquibase for schema migrations?
- AThey safely version, review, and roll back changes.
- BThey automate data type changes.
- CThey prevent any table locking.
- DThey eliminate the need for SQL knowledge.
8.What happens when you add a NOT NULL constraint to an existing column in PostgreSQL?
- AThe column is dropped and recreated.
- BThe operation is always instant.
- CThe table is locked for validation.
- DThe column is instantly updated.