Dropping a column from a table Which SQL statement uses standard syntax to remove an existing column from a table definition?

Difficulty: Easy

Correct Answer: ALTER TABLE TableName DROP COLUMN ColumnName

Explanation:


Introduction / Context:
Changing a table's structure is a Data Definition Language (DDL) task. Dropping a column must follow the DBMS's accepted ALTER TABLE syntax. Using a portable, standards-aligned form reduces surprises across platforms.



Given Data / Assumptions:

  • We want to remove a column permanently from a table.
  • We will handle dependencies such as indexes, constraints, or generated columns first if required by the DBMS.
  • We aim for widely supported wording.


Concept / Approach:

The canonical form is ALTER TABLE ... DROP COLUMN ... . Many vendors also accept slight variations, but the explicit DROP COLUMN keyword pair is the most standard and clear. Always review constraints and foreign keys that reference the column before dropping.



Step-by-Step Solution:

Issue: ALTER TABLE TableName DROP COLUMN ColumnName;Confirm there are no dependent indexes or constraints; drop them first if necessary.Verify application code and views do not reference the removed column.Apply in a maintenance window if the table is large to avoid long locks.


Verification / Alternative check:

Most mainstream DBMS documentation (e.g., PostgreSQL, SQL Server, Oracle, MySQL) supports ALTER TABLE ... DROP COLUMN, sometimes with additional options (CASCADE, RESTRICT).



Why Other Options Are Wrong:

  • A/B/E: MODIFY/CHANGE TABLE are not standard SQL statements.
  • D: Some vendors allow DROP without COLUMN, but DROP COLUMN is clearer and more portable.


Common Pitfalls:

  • Dropping a column that is part of a foreign key or primary key without first adjusting constraints.
  • Forgetting to update ORM mappings and ETL scripts.


Final Answer:

ALTER TABLE TableName DROP COLUMN ColumnName

More Questions from Database Redesign

Discussion & Comments

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