select*fromstudent_detail;+-----------+--------- ----"/> select*fromstudent_detail;+-----------+--------- ----">

Home >Database >Mysql Tutorial >How to delete existing column from MySQL table?

How to delete existing column from MySQL table?

PHPz
PHPzforward
2023-09-06 16:49:111212browse

如何从 MySQL 表中删除现有列?

We can delete specific existing columns from a MySQL table by using DROP statement and ALTER statement. Its syntax is 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 from which the column is to be deleted. will be removed from the table.

Example

In this example, we delete the "address" column from the table "student_detail" as follows Display-

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 the "address" column has been deleted from the table.

The above is the detailed content of How to delete existing column from MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete