MySQL
ORACLE
POSTGRESQL
SQL
SQL SERVER

A Complete Guide to the ALTER TABLE DROP COLUMN Statement

intro

Let’s see everything you need to know about the ALTER TABLE DROP COLUMN query to remove a column from a table in SQL.

Tools used in the tutorial
Tool Description Link
Dbvisualizer DBVISUALIZER
TOP RATED DATABASE MANAGEMENT TOOL AND SQL CLIENT

Database schemas evolve to accommodate new business needs and data representation requirements. As a result, some columns in a table may become obsolete and need to be removed to save space. This is where the SQL ALTER TABLE DROP COLUMN statement comes in!

In this guide, you'll learn what the DROP COLUMN ALTER TABLE statement is and how to use it in MySQL, PostgreSQL, SQL Server, and Oracle.

Let’s dive in!

What Is the ALTER TABLE DROP COLUMN Statement?

The SQL ALTER TABLE DROP COLUMN statement is used to remove columns from an existing table in a database. This operation modifies the table structure by permanently deleting the specified columns.

In some databases, the DROP COLUMN ALTER TABLE command only affects the table metadata. In others, it also immediately removes the data stored in the column to reclaim disk space. Learn more about the process of deleting a column in SQL.

SQL ALTER TABLE DROP COLUMN Syntax and Usage

This is the syntax of SQL ALTER TABLE DROP COLUMN query according to the ANSI/ISO standard:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] column_name [CASCADE | RESTRICT];

Where:

  • table_name is the name of the table which we drop the column from.
  • COLUMN is an optional keyword to increase query readability.
  • column_name is the name of the column you want to remove from table_name.
  • CASCADE | RESTRICT are the optional drop behavior modifiers. If CASCADE is specified, the database will automatically drop any dependent objects related to the column you are dropping (e.g., stored procedures, views, triggers, etc.) Instead, the RESTRICT option prevents the column from being dropped if there are any dependencies on it.

At the same time, all major SQL dialects come with some variations and extensions of that syntax. Time to explore how to use the ALTER TABLE DROP COLUMN action in:

  • MySQL
  • PostgreSQL
  • Oracle
  • SQL Server

MySQL

Below is the syntax of the MySQL ALTER TABLE query for dropping a column:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] column_name;

As you can see, MySQL does not support the CASCADE and RESTRICT options.

Example:

Copy
        
1 ALTER TABLE employees 2 DROP age;

The above query removes the age column from the employees table.

MySQL also supports an extension to the standard syntax to drop multiple columns in a single ALTER TABLE statement:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] column_1, [...], DROP [COLUMN] column_n;

Example:

Copy
        
1 ALTER TABLE employees 2 DROP middle_name, DROP salary;

This deletes the middle_name and salary columns from the employees table.

Notes:

  • In MySQL 8.4, DROP COLUMN statements are executed online, updating each row accordingly and not just the table metadata.
  • Using ALTER TABLE DROP COLUMN in MySQL requires ALTER permission on the table.
  • Columns cannot be dropped from tables that use ROW_FORMAT=COMPRESSED, tables with a FULLTEXT index, tables that reside in the data dictionary tablespace, or temporary tables.

PostgreSQL

The ALTER TABLE syntax for dropping columns in PostgreSQL is:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] [IF EXISTS] column_name [RESTRICT | CASCADE];

IF EXISTS is an optional Postgres extension. If it is specified and the column does not exist, no error is thrown.

Example:

Copy
        
1 ALTER TABLE users 2 DROP COLUMN IF EXISTS points;

This DROP COLUMN ALTER TABLE query removes the points column from the users table, if the column exists.

The syntax for dropping multiple columns in PostgreSQL is:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] [IF EXISTS] column_1 [RESTRICT | CASCADE], 3 [...], 4 DROP [COLUMN] [IF EXISTS] column_n [RESTRICT | CASCADE];

Example:

Copy
        
1 ALTER TABLE users 2 DROP COLUMN address, 3 DROP COLUMN IF EXISTS age;

The above query deletes the address column and removes the age column—if it exists—from the users table.

Notes:

  • The DROP COLUMN does not physically remove the column but simply makes it invisible to SQL operations. Subsequent insert and update operations in the table will store a NULL value for the column. Thus, dropping a column in PostgreSQL is quick as it does not immediately free up space on disk.
  • ALTER TABLE DROP COLUMN can be used to drop the only column of a table, leaving the table with no columns. This is an extension of SQL, which disallows zero-column tables.

SQL Server

This is how to use ALTER TABLE DROP COLUMN in SQL Server:

Copy
        
1 ALTER TABLE table_name 2 DROP COLUMN [IF EXISTS] column_name;

In this case, COLUMN is required and there is no support for the RESTRICT and CASCADE options.

Example:

Copy
        
1 ALTER TABLE Products 2 DROP COLUMN Description;

This removes the Description column from the Products table.

Compared to MySQL and PostgreSQL, the syntax for removing multiple columns with a single ALTER TABLE query is a bit different in SQL Server:

Copy
        
1 ALTER TABLE table_name 2 DROP COLUMN [IF EXISTS] column_1, [...], column_n;

Example:

Copy
        
1 ALTER TABLE Products 2 DROP COLUMN Discount, Category;

The SQL Server query drops the Discount and Category columns from Products.

Notes:

  • You cannot delete a column that has a CHECK constraint. First, you must delete the constraint.
  • You cannot delete a column that has PRIMARY KEY or FOREIGN KEY constraints, as well as other dependencies. You must first remove all dependencies on the column to proceed. Check out the documentation for more limitations.
  • When you drop a column from a table, the column and all its data are deleted.
  • To remove a column in SQL Server, you need an ALTER permission on the table.

Oracle

Here is the ALTER TABLE DROP COLUMN syntax in Oracle:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] column_name;

Example:

Copy
        
1 ALTER TABLE events 2 DROP COLUMN date;

This command removes the date column from the events table.

Oracle allows you to drop multiple columns in a single ALTER TABLE statement by using the following syntax:

Copy
        
1 ALTER TABLE table_name 2 DROP (column_1, column_2, [...], column_n);

Example:

Copy
        
1 ALTER TABLE events 2 DROP (description, type);

This drops the description and type columns from the events table.

Notes:

  • You can drop columns even on temporary tables.
  • Oracle distinguishes between dropped columns and unused columns.
  • You can drop a column from an index-organized table only if it is not a primary key column.
  • You cannot drop a column a domain index has been built on.

Drop a Column in a Table Using a Database Client

As you just learned, each major database technology has its variations of the standard syntax for dropping a column. Remembering the specific DROP COLUMN ALTER TABLE syntax across different databases can be challenging, and mistakes in writing the query are common.

How can you avoid that issue? With DbVisualizer, a database client that allows you to visually remove columns from a table. Regardless of the underlying database, the procedure remains the same and involves only a few clicks!

To drop a column in DbVisualizer:

  1. Install DbVisualizer locally.

  2. Launch DbVisualizer and set up a connection to one of the more than 50 databases supported.

  3. Connect to your database server, expand the "Databases" dropdown menu on the left, select the specific database to explore, and expand the "Tables" dropdown: In this case, the database is called games.

    Note the list of databases and tables

    Note the list of databases and tables

  4. Right-click on the table to remove the column in, and select the "Alter table…" option. In this example, the selected table is users.

    Selecting the Alter Table option

    Selecting the Alter Table option

  5. In the "Alter Table" dialog, select the column you want to remove, and click the "—" button on the right to mark it as to be dropped. The columns to drop are created_by and created_at.

    Note the queries in the SQL Preview section

    Note the queries in the SQL Preview section

  6. Click "Execute" and DbVisualizer will remove the selected columns for you.

In particular, as you can see, it will execute the following queries:

Copy
        
1 ALTER TABLE 2 `games`.`users` DROP COLUMN `created_by`; 3 ALTER TABLE 4 `games`.`users` DROP COLUMN `created_at`;

Et voilà! You just learned a more intuitive way to remove columns in SQL.

Conclusion

In this guide, you learned how to use ALTER TABLE to drop columns in SQL. You explored what this statement offers and how to use it in MySQL, PostgreSQL, SQL Server, and Oracle.

As discussed here, each SQL dialect has its own extensions and syntax variations for the DROP COLUMN ALTER TABLE command. The easiest way to delete a column in SQL is through a full-featured database client that allows you to do it visually with just a few clicks. This is exactly what DbVisualizer offers!

As a powerful database client, DbVisualizer supports many DBMS technologies, can generate ERD-like schemas with a single click, and also provides advanced query optimization features. Try DbVisualizer for free today!

FAQ

Is it possible to drop multiple columns with a single DROP COLUMN ALTER TABLE query?

The official SQL ANSI/ISO standard does not specify a way to drop multiple columns in a single ALTER TABLE query. However, most SQL dialects support this feature natively with their own custom syntax.

What are the permissions required to use ALTER TABLE DROP COLUMN in SQL Server?

To use ALTER TABLE DROP COLUMN in SQL Server, you need the ALTER permission on the table, which enables you to make changes to the table structure.

What is the opposite of DROP COLUMN in ALTER TABLE?

The SQL ALTER TABLE DROP COLUMN statement removes a column from a table. That means the opposite operation is the ALTER TABLE ADD COLUMN statement, which adds a column to a table. Discover more in our guide on the ALTER TABLE ADD COLUMN statement.

What are the most common conditions why you cannot drop a column in SQL?

Each database has its own set of rules that columns must meet in order to be dropped. These are the conditions that may prevent an SQL column from being dropped:

  • The user does not have the ALTER privilege on the specified table.
  • The column is part of a PRIMARY KEY constraint.
  • The column is part of a FOREIGN KEY constraint.
  • The column is part of a CHECK constraint.
  • The column is indexed, part of a trigger, or used in a view, computed column, stored procedure, or partitioning key.
  • The column is the only column in a table.

Is it possible to use ALTER TABLE to DROP COLUMN without losing data if the column is not empty?

No, it is not possible to use ALTER TABLE to DROP COLUMN without losing data if the column is not empty. Dropping a column permanently deletes both the column and all data contained in it. Once the column is dropped, the data cannot be recovered unless you have a backup. If you are a MySQL user, find out more in our mysqldump guide.

Dbvis download link img
About the author
Antonello Zanini

Antonello is a software engineer, and often refers to himself as a technology bishop. His mission is to spread knowledge through writing.

The Table Icon
Sign up to receive The Table's roundup
More from the table
Title Author Tags Length Published
title

MySQL NOW Function: Get the Current Date and Time

author Antonello Zanini tags DATETIME MySQL 5 min 2025-02-27
title

A Complete Guide to the MySQL CTE Mechanism

author Antonello Zanini tags MySQL 10 min 2025-02-26
title

SQL Operators: A Complete Walkthrough

author Lukas Vileikis tags DbVisualizer MySQL SQL 4 min 2025-02-25
title

How to Truncate Many Tables In SQL at Once

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-02-24
title

PostgreSQL Truncate Table Reset Sequence Guide

author Antonello Zanini tags POSTGRESQL 6 min 2025-02-17
title

Clustered vs Non-Clustered Index: Complete SQL Guide

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2025-02-13
title

Queries and Subqueries in SQL: The Definitive Guide

author Lukas Vileikis tags DbVisualizer MySQL POSTGRESQL SQL SQL SERVER 7 min 2025-02-12
title

How to Optimize a Clustered Index Scan in SQL

author Antonello Zanini tags MySQL SQL SQL SERVER 7 min 2025-02-11
title

SQL Derived Table: Everything You Need to Know

author Antonello Zanini tags MySQL POSTGRESQL SQL SQL SERVER 9 min 2025-02-06
title

How To List Databases in PostgreSQL: A Complete Guide

author Antonello Zanini tags POSTGRESQL 8 min 2025-02-05

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.