In standard SQL Data Definition Language (DDL), which command correctly adds a new column to an existing table (syntax shown generically without a data type)?

Difficulty: Easy

Correct Answer: ALTER TABLE TableName ADD COLUMN ColumnName

Explanation:


Introduction / Context:
Schema evolution often requires adding new columns. Using the correct Data Definition Language (DDL) syntax avoids errors and ensures portability across relational databases, especially those that follow SQL standards closely.



Given Data / Assumptions:

  • You have an existing table and need to add a column.
  • Some DBMSs require specifying the data type (for example, ADD COLUMN status TEXT).
  • We are focusing on the canonical SQL form.


Concept / Approach:
The standard command to change a table definition is ALTER TABLE. To add a column, use ADD COLUMN followed by the column name (and typically a data type and optional constraints). Some engines permit ADD without the word COLUMN, but ADD COLUMN is widely supported and self-documenting.



Step-by-Step Solution:

Identify the target table.Issue: ALTER TABLE TableName ADD COLUMN ColumnName DataType [constraints];Backfill or update data as needed, and consider defaults or NOT NULL with care.


Verification / Alternative check:
Execute the statement in a development environment and describe the table to confirm the new column appears with the correct definition.



Why Other Options Are Wrong:

  • MODIFY TABLE: Not standard SQL; some vendors use ALTER TABLE exclusively.
  • ADD ColumnName without COLUMN: May work on some DBMSs, but the canonical form includes COLUMN and increases portability.
  • APPEND COLUMN: Not a standard SQL keyword for this operation.


Common Pitfalls:
Adding a NOT NULL column without a DEFAULT to a large table can fail or lock for long periods. Plan migrations with defaults and backfill strategies.



Final Answer:
ALTER TABLE TableName ADD COLUMN ColumnName

More Questions from Database Redesign

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion