Home > Database > Mysql Tutorial > body text

How to remove fields in mysql

青灯夜游
Release: 2021-12-28 16:44:06
Original
49255 people have browsed it

In mysql, you can use the "ALTER TABLE" statement and the "DROP" keyword to remove specified fields. The syntax is "ALTER TABLE data table name DROP field name;". "Field name" refers to the table that needs to be removed. The name of the field to be removed from .

How to remove fields in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In mysql, you can use the "ALTER TABLE" statement and the "DROP" keyword to remove specified fields.

  • ALTER TABLE statement to change the structure of the original table, such as adding or deleting columns, changing the original column type, renaming columns or tables, etc.

  • dropThe statement will delete the table structure, as well as the dependent constraints, triggers, and indexes;

Removing a field is to remove a field in the data table from the table. The syntax format is as follows:

ALTER TABLE 数据表名 DROP 字段名;
Copy after login

Among them, "field name" refers to the need The name of the field to be removed from the table.

Example: Remove the deptId field in the tb_emp data table

First check the data of the tb_emp data table

mysql> DESC tb_emp;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int(11)     | YES  |     | NULL    |       |
| name   | varchar(30) | YES  |     | NULL    |       |
| deptId | int(11)     | YES  |     | NULL    |       |
| salary | float       | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
Copy after login

Remove the deptId field

mysql> ALTER TABLE tb_emp
    -> DROP deptId;
Query OK, 0 rows affected (0.53 sec)
Records: 0  Duplicates: 0  Warnings: 0
Copy after login

View new data after removing fields

mysql> DESC tb_emp;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int(11)     | YES  |     | NULL    |       |
| name   | varchar(30) | YES  |     | NULL    |       |
| salary | float       | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
Copy after login

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to remove fields in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!