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 .
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.
drop
The 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 字段名;
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)
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
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)
[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!