Difficulty: Easy
Correct Answer: Correct — adding NULL-allowed columns is usually simple and low risk
Explanation:
Introduction / Context:
Production databases often evolve. The ease of adding a column depends on whether default values are required and whether the column allows NULL. Nullable additions are typically the least disruptive change.
Given Data / Assumptions:
Concept / Approach:
When a column is nullable, existing rows do not need to be rewritten with a default value; they can logically treat the new attribute as “unknown/not applicable.” As a result, ALTER TABLE ADD COLUMN operations can often be fast and online (varies by DBMS), especially for metadata-only changes.
Step-by-Step Solution:
Assess whether the column can be NULL and whether a default is necessary.Execute ALTER TABLE ... ADD COLUMN ... NULL.Optionally backfill data in batches to avoid large blocking writes.Deploy application changes to read/write the new column gradually.
Verification / Alternative check:
DBMS documentation commonly cites that adding nullable columns is lighter weight than adding NOT NULL columns with defaults (which may rewrite the table).
Why Other Options Are Wrong:
Requiring full reloads or downtime is not universally true; many systems support online or low-impact schema changes. Index presence or isolation level do not determine feasibility by themselves.
Common Pitfalls:
Adding NOT NULL with default on huge tables may rewrite pages; plan carefully. Also verify ORM mappings and ensure application code handles NULL.
Final Answer:
Correct — adding a nullable column is generally straightforward.
Discussion & Comments