How to DROP COLUMN in MariaDB

Galaxy Glossary

How do I drop a column in MariaDB without locking my table?

DROP COLUMN removes one or more columns from an existing MariaDB table.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

When should I use DROP COLUMN?

Use DROP COLUMN when a field is obsolete, storing redundant data, or replaced by another column. Removing it keeps schemas lean and queries fast.

What is the basic syntax?

The command is issued with ALTER TABLE, followed by one or more DROP COLUMN clauses.Options let you control locking and algorithm behavior.

How do I drop a single column?

ALTER TABLE Products DROP COLUMN stock;

This permanently deletes the stock column and its data.

Can I drop multiple columns at once?

ALTER TABLE Customers
DROP COLUMN email,
DROP COLUMN created_at;

Batch execution runs faster than two separate statements.

How do I avoid table locks?

ALTER TABLE Orders
DROP COLUMN total_amount,
ALGORITHM=INPLACE,
LOCK=NONE;

INPLACE keeps the table writable; LOCK=NONE prevents read/write blocks.

What if other objects depend on the column?

DROP COLUMN fails if foreign keys, indexes, or generated columns rely on it.Remove those dependencies first or use CASCADE.

Best practices for production?

• Take backups before schema changes.
• Drop in off-peak hours or with minimal locking options.
• Verify application code no longer references the column.

Is there a reversible alternative?

You cannot UNDROP a column.Simulate a rollback with backup/restore or by creating a new column and migrating data instead of dropping.

Example: cleaning up legacy discount column

-- Remove no longer used discount field
ALTER TABLE OrderItems
DROP COLUMN discount,
ALGORITHM=INPLACE,
LOCK=NONE;

The table stays online while the obsolete discount column disappears.

.

Why How to DROP COLUMN in MariaDB is important

How to DROP COLUMN in MariaDB Example Usage


-- Remove the deprecated 'created_at' column and avoid locking
ALTER TABLE Customers 
    DROP COLUMN created_at,
    ALGORITHM=INPLACE,
    LOCK=NONE;

How to DROP COLUMN in MariaDB Syntax


ALTER TABLE table_name
    DROP [COLUMN] column_name
    [, DROP [COLUMN] column_name2 ...]
    [CASCADE | RESTRICT]
    [ALGORITHM={DEFAULT|INPLACE|COPY}]
    [LOCK={DEFAULT|NONE|SHARED|EXCLUSIVE}];

-- Ecommerce example
ALTER TABLE Products 
    DROP COLUMN stock,
    ALGORITHM=INPLACE,
    LOCK=NONE;

Common Mistakes

Frequently Asked Questions (FAQs)

Does DROP COLUMN free disk space immediately?

Space is reclaimed after OPTIMIZE TABLE or when MariaDB performs internal cleanup during future writes.

Can I drop a generated column?

Yes, but ensure no other column or index depends on it. Use the same ALTER TABLE ... DROP COLUMN syntax.

Is CASCADE safe?

CASCADE automatically removes dependent foreign keys and indexes. Review each dependency beforehand to avoid unexpected loss of constraints.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.