
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can I drop an existing column from a MySQL table?
We can delete a particular existing column from a MySQL table by using the DROP statement along with an ALTER statement. Its syntax would be as follows −
Syntax
ALTER TABLE table_name DROP column_name;
Here, table_name is the name of the table from which we want to delete the column.
Column_name is the name of the column which is to be deleted from the table.
Example
In this example, we are deleting the column ‘address’ from table ‘student_detail’ as follows −
mysql> select * from student_detail; +-----------+-------------+----------+ | Studentid | StudentName | address | +-----------+-------------+----------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | | 103 | Rahul | Jaipur | | 104 | Ram | Ludhiana | | 105 | Mohan | Patiala | +-----------+-------------+----------+ 5 rows in set (0.19 sec) mysql> ALTER TABLE student_detail DROP address; Query OK, 0 rows affected (1.43 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from student_detail; +-----------+-------------+ | Studentid | StudentName | +-----------+-------------+ | 100 | Gaurav | | 101 | Raman | | 103 | Rahul | | 104 | Ram | | 105 | Mohan | +-----------+-------------+ 5 rows in set (0.00 sec)
The above result set shows that column ‘address’ has been deleted from the table.
- Related Articles
- How can I change the name of an existing column from a MySQL table?
- How can we remove NOT NULL constraint from a column of an existing MySQL table?
- How can we remove PRIMARY KEY constraint from a column of an existing MySQL table?
- How can we remove FOREIGN KEY constraint from a column of an existing MySQL table?
- How can I see the CREATE TABLE statement of an existing MySQL table?
- How can we create a table from an existing MySQL table in the database?
- How to rename a column in an existing MySQL table?
- How can we create a new MySQL table by selecting specific column/s from another existing table?
- How can we drop UNIQUE constraint from a MySQL table?
- How can we put comments in a column of existing MySQL table?
- How can we apply a NOT NULL constraint to a column of an existing MySQL table?
- How do I remove ON UPDATE CURRENT_TIMESTAMP from an existing column in MySQL?
- Adding new enum column to an existing MySQL table?
- Create MySQL query to create a table from an existing table?
- How can we remove a column from MySQL table?

Advertisements