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

How to delete existing column from MySQL table?

PHPz
Release: 2023-09-06 16:49:11
forward
1216 people have browsed it

如何从 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;
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template