DROP COLUMN

SQL · Working with Tables

Theory

ALTER TABLE ... DROP COLUMN permanently removes a column and all the data stored in it from every row. ALTER TABLE employees DROP COLUMN fax_number leaves the other columns and all rows untouched. Many engines accept DROP COLUMN IF EXISTS for re-runnable scripts.

Dependencies can block the drop: a view, index, foreign key, CHECK constraint or primary key that uses the column. Depending on the engine you must remove those first, or add CASCADE to drop dependent objects as well (PostgreSQL). Some engines only mark the column as unused and reclaim space later. Application code or reports that still select the column will start failing, so search for its uses before dropping. You cannot drop the last remaining column of a table.

Why we use it

Unused or obsolete columns confuse users, waste storage and can hold sensitive data that should not be kept. DROP COLUMN cleans them out of the schema for good.

When to use it

Use DROP COLUMN when a field is truly no longer needed and nothing depends on it. If you are unsure, rename it or stop writing to it first, and keep a backup. To remove rows instead of a column, use DELETE.

How it works

  1. ALTER TABLE employees DROP COLUMN fax_number
  2. Do views or constraints use it? Yes: Drop them first or use CASCADE. No: Continue.
  3. Remove the column definition
  4. Discard the stored values for every row
  5. Queries using the column now fail

Syntax

ALTER TABLE table_name
DROP COLUMN column;

Example

ALTER TABLE employees DROP COLUMN fax_number;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic