DELETE
MySQL
ORACLE
POSTGRESQL
SQL
SQL SERVER

Deleting a Column in SQL: Everything You Need to Know

intro

Let’s learn what happens when deleting a column in SQL and how to do it in the most popular DBMS technologies.

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

Deleting a column in SQL is one of the most common operations when dealing with a database. For this reason, knowing how to delete a column from a table in SQL is a key skill to have. Without the right procedures and precautions, you could run into data integrity and data loss issues.

In this guide, you will dig into the process of how to delete a column in SQL, exploring the essential concepts and how to do it. At the end of this guide, you will have all the information required to perform column deletion operations smoothly and effectively.

Let’s dive in!

What Does It Mean to Delete a Column in SQL?

Deleting a column in SQL refers to the process of permanently removing a specific column from a table. All data associated with the column will be removed from the disk. Similarly, the column’s metadata will be removed from the table's schema.

When you delete a column, you essentially eliminate its existence within the table structure. The column will be no longer available for queries and its data will be lost.

Consequences of Deleting a Column in SQL

Here are the key aspects to consider when removing a column from a table in SQL:

  • Data removal: All data currently stored in the column, in each row of the table, will be permanently deleted. This includes all values, records, or information previously stored in that column.
  • Metadata removal: The column's metadata, such as its name, data type, default values, constraints, and indexes will be removed from the table's schema definition. This modification impacts the structure of the table, changing the number of its columns.
  • Query impact: Any queries, statements, or SQL procedures that reference the deleted column must be updated accordingly. In detail, you need to exclude the column from the query to avoid errors or unexpected results.
  • Data integrity: If the column is part of foreign keys or other constraints, deleting it involves data integrity considerations. In some DBMSs, you may need to remove these constraints or manage them accordingly before you can delete the column.
  • Performance and storage improvements: Deleting a column in SQL can lead to improved query performance, especially if the column is retrieved but not used. Removing the data associated with the column also results in reduced storage.

Keep in mind that deleting a column is an operation that cannot be undone. This means that you must be careful with it, especially in production environments. Before proceeding with the irreversible operation, it is essential to plan properly, back up the database, and consider the potential impact on existing applications and queries.

For further reading on how to perform and and deal with backups in databases, check out our guides:

Syntax to Delete a Column in SQL

The SQL command to delete an existing column from a table is DROP COLUMN, with is part of the SQL DDL. That stands for “Data Definition Language” and contains statements to define, modify, or delete the structure of database objects like tables, indexes, and constraints.

Since DROP COLUMN involves modifying the structure of an existing table, it must be used in an ALTER TABLE query.

Here is the generic SQL syntax to delete a column from a table:

Copy
        
1 ALTER TABLE table_name DROP COLUMN column_name;

Where:

  • table_name is the name of the table you want to remove the column_name column from;
  • column_name is the name of the column to remove.

For more information, refer to our specific guide on how to the ALTER TABLE DROP COLUMN statement.

Later in this article, you will see how to use this query in the most popular relational databases, such as MySQL, PostgreSQL, SQL Server, and Oracle.

How to Delete a Column From a Table in SQL

In this section, you will see how to delete one or more columns in the most popular relational databases:

  • MySQL
  • PostgreSQL
  • SQL Server
  • Oracle

Time to see how to delete a column in SQL technologies!

Deleting a Column in MySQL

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

Note that the COLUMN keyword is optional. For more details about this query, read our article on the MySQL ALTER TABLE statement.

For example, you can remove the email column from the users table with:

Copy
        
1 ALTER TABLE users 2 DROP COLUMN email;

The syntax to delete multiple columns with a single query in MySQL is:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] column1, 3 DROP [COLUMN] column2, 4 ..., 5 DROP [COLUMN] columnN;

Again, COLUMN is optional.

So, the query to remove the phone and address columns from the contacts table is:

Copy
        
1 ALTER TABLE contacts 2 DROP phone, 3 DROP address;

Deleting a Column in PostgreSQL

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

The COLUMN keyword is optional.

For example, you can remove the address column from the users table with:

Copy
        
1 ALTER TABLE users 2 DROP COLUMN address;

Instead, the syntax to delete more than one column with a single PostgreSQL query is:

Copy
        
1 ALTER TABLE table_name 2 DROP [COLUMN] column1, 3 DROP [COLUMN] column2, 4 ..., 5 DROP [COLUMN] columnN;

Again, COLUMN is optional.

Thus, below is the query to delete the price and quantity columns from the orders table:

Copy
        
1 ALTER TABLE orders 2 DROP COLUMN price, 3 DROP COLUMN quantity;

Deleting a Column in SQL Server

Copy
        
1 ALTER TABLE table_name 2 DROP COLUMN column_name;

For instance, you can drop the release_date column from the games table with:

Copy
        
1 ALTER TABLE games 2 DROP COLUMN release_date;

To delete multiple columns with a single T-SQL query is, the syntax is:

Copy
        
1 ALTER TABLE table_name 2 DROP COLUMN column1, column2, ..., columnN;

Note: The above syntax is different from that of MySQL and PostgreSQL.

Therefore, this is the query to remove the time and efforts columns from the projects table:

Copy
        
1 ALTER TABLE projects 2 DROP COLUMN time, effort;

Deleting a Column in Oracle

Copy
        
1 ALTER TABLE table_name 2 DROP COLUMN column_name;

For example, you can remove the price column from the products table with:

Copy
        
1 ALTER TABLE products DROP COLUMN price;

Instead, the syntax to delete multiple columns at the same time is:

Copy
        
1 ALTER TABLE table_name 2 DROP (column1, column2, ..., columnN);

Note how COLUMN disappears from the ALTER TABLE ... DROP COLUMN query for a single query. Also, you must list the columns to delete, separated by commas, between parentheses

Then, the following query deletes the address and age from the users table:

Copy
        
1 ALTER TABLE projects 2 DROP (address, age);

Note that Oracle also allows you to logically delete a column with the SET UNUSED command.

Visually Remove a Column in SQL: Complete Example

When deleting a column in SQL, you must follow the appropriate procedure. You cannot simply execute a DROP COLUMN statement without careful consideration, as it will permanently remove data from your table.

Ideally, you should be able to see the impact of your query visually to understand how it affects your database schema. This is where a database client like DbVisualizer becomes invaluable!

DbVisualizer allows you to visually explore your tables and data, making it easier to monitor your database and address issues as they arise. This visual insight helps ensure that changes are made thoughtfully and with full awareness of their consequences.

Also, DbVisualizer lets you delete a column visually, without needing to manually execute a query. Let’s see how!

Step #1: Reach and Explore Your Table

Download DbVisualizer for free and follow the wizard to set up a database connection.

Suppose you have a companyMySQL database. Navigate to the users table and open the “Columns” dropdown. Right-click on “Columns” and select the “Open in New Tab” option:

The Columns tab in DbVisualizer
The Columns tab in DbVisualizer

Here, you can visually explore all the columns your employees table consists of.

Step #2: Visually Altering the Table

Right click on the employees table and select the “Alter Table...” option:

Selecting the Alter Table… option
Selecting the Alter Tableu2026 option

This will open the following modal:

The Alter Table modal
The Alter Table modal

Here, select the active column, click the “-” button, and then run the “Execute” button:

Visually deleting a column in SQL using DbVisualizer
Visually deleting a column in SQL using DbVisualizer

Under the hood, DbVisualizer will run the following query you can see in the “SQL Preview” section:

Copy
        
1 ALTER TABLE 2 `company`.`employees` DROP COLUMN `active`

In other words, it performs the correct DROP COLUMN statement for you. Equivalently, you can open the SQL Commander and launch manually launch the query:

Manually launching the DROP COLUMN query
Manually launching the DROP COLUMN query

In both cases, the is_active column will be removed from employees.

Step #3: Verify Column Removal

To make sure that the column was removed, right-click on “Columns” and select the “Refresh Objects Tree” option:

Refreshing the database objects tree
Refreshing the database objects tree

This will refresh the column list, and you should notice that is_active is now gone:

The is_active column is no longer in the list
The is_active column is no longer in the list

Et voilà! You just deleted a column visually with just a few simple clicks!

Best Practices When You Delete a Column in SQL

Best practices help prevent data loss and minimize disruptions when deleting a column in SQL, especially in a production environment. Some considerations to keep in mind before proceeding are:

  • Backup your database: Always create a full backup to restore data if needed. Keep in mind that deleting columns can lead to serious data losses.
  • Assess dependencies: Check for foreign keys, constraints, indexes, or views that reference the column. If the column you want to delete is part of those conditions, the SQL query to delete a column from a table will fail. Consider using an auto-generated ERD-like schema for this task.
  • Communicate changes: Notify teams relying on the database to avoid unexpected issues.
  • Test in a staging environment: Ensure the deletion does not break functionality before moving the update to production
  • Plan for rollback: Have a strategy to immediately restore the column if necessary in case of errors.

Conclusion

In this article, you saw what it means to delete a column in SQL, what happens when you do it, and how to do it. Thanks to what you learned here, you now know how to handle single and multiple column deletion in MySQL, PostgreSQL, Microsoft SQL Server, and Oracle Database.

Since deleting columns in SQL alters schema of your database, monitoring the consequences in a database client makes everything easier. This is where DbVisualizer comes in!

In addition to supporting visual querying, column management, and data exploration in dozens of databases, DbVisualizer also offers advanced query optimization capabilities, and ER-like schema generation. Download DbVisualizer for free now!

FAQ

What is the difference between dropping a column and deleting a column in SQL?

In SQL, dropping a column and deleting a column mean the same things. The two expressions refer to the process of permanently removing a column from a table, including its data and metadata.

How to delete a value from a column in SQL?

To "delete a value from a column" in SQL means setting it to NULL, assuming the column is nullable. You can achieve that using the UPDATE statement below:

Copy
        
1 UPDATE table_name 2 SET column_name = NULL 3 WHERE condition;

If the column does not allow NULL, you would need to set it to a default or alternative value. Discover more in our blog post on working with NULL.

What is the difference between deleting a column logically and deleting a column physically?

The distinction between logical and physical deletion in a relational database lies in how data removal is applied. Logical deletion involves marking the data as inactive without physically removing the column. On the other hand, physical deletion involves permanently removing the data from the database, making it unrecoverable.

Is it possible to delete multiple columns in a single SQL statement?

In most SQL dialects, you can remove more than one column with a single ALTER TABLE query by using a special syntax. In such a scenario, you have to specify all the columns you want to delete in a list or use the DROP COLUMN command several times.

What happens when you try to delete a column that does not exist?

When attempting to delete a column that does not exist in the table, the database will raise an error. For example, MySQL returns the following error message:

Copy
        
1 Can't DROP 'column_name'; check that column/key exists

Thus, ensure that the columns you want to delete exist in the table before launching the command.

How to delete a column in a foreign key constraint?

To delete a column that is part of a foreign key constraint, you must first drop the constraint:

Copy
        
1 ALTER TABLE child_table DROP CONSTRAINT fk_constraint_name;

Once the foreign key is removed, you can safely delete the column:

Copy
        
1 ALTER TABLE child_table DROP COLUMN column_name;

Before launching the SQL query to delete a column from a table, check that the column is not referenced elsewhere (e.g., indexes, constraints).

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

How To List Tables In Postgres: Complete Guide

author Leslie S. Gyamfi tags POSTGRESQL 6 min 2025-04-17
title

A Complete Guide to an SQL Recursive Query Expression

author Lukas Vileikis tags MySQL SQL 5 min 2025-04-16
title

A Guide to the SQL Standard Deviation Functions

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-04-15
title

SQL EXISTS: Syntax and Use Cases with Examples

author Leslie S. Gyamfi tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-04-14
title

Welcoming Tables with Foreign Keys Into Your Database

author Lukas Vileikis tags MySQL SQL 5 min 2025-04-10
title

Dealing With NULL in SQL: Complete Guide

author Leslie S. Gyamfi tags SQL 7 min 2025-04-09
title

A Complete Guide to the New MySQL 9 VECTOR Data Type

author Antonello Zanini tags MySQL MySQL 9 5 min 2025-04-08
title

Data Backup and Recovery: Implement the Golden Rule in Your Database

author Lukas Vileikis tags Backup Recovery SQL 6 min 2025-04-07
title

How to Delete Table Data in SQL: A Complete Guide

author Lukas Vileikis tags SQL 5 min 2025-04-03
title

SQL Query Optimization: Everything You Need to Know

author Leslie S. Gyamfi tags OPTIMIZATION SQL 9 min 2025-04-02

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.