MySQL命令行删除表中的一个字段

2023年 4月 26日 67.0k 0

先看看删除之前的表结构: mysql select * from test; +------+--------+----------------------------------+------------+------------+------------+------------+ | t_id | t_name | t_password | t_birth | birth | birth1 | birth2 | +----

先看看删除之前的表结构:
mysql> select * from test;
+------+--------+----------------------------------+------------+------------+------------+------------+
| t_id | t_name | t_password                       | t_birth    | birth      | birth1     | birth2     |
+------+--------+----------------------------------+------------+------------+------------+------------+
|    1 | name1  | 12345678901234567890123456789012 | NULL       | 1990-01-01 | 0000-00-00 | 2013-01-01 |
|    2 | name2  | 12345678901234567890123456789012 | 2013-01-01 | NULL       | 0000-00-00 | 2013-01-01 |
+------+--------+----------------------------------+------------+------------+------------+------------+
2 rows in set (0.00 sec)
执行删除命令,使用drop关键字。
基本的语法为:alter table <表名> drop column <字段名>;
具体的命令如下:
mysql> alter table test drop column birth1;
Query OK, 0 rows affected (0.13 sec)
Records: 0  Duplicates: 0  Warnings: 0
看看删除后的结果,是不是已经没有birth1字段了?
mysql> select * from test;
+------+--------+----------------------------------+------------+------------+------------+
| t_id | t_name | t_password                       | t_birth    | birth      | birth2     |
+------+--------+----------------------------------+------------+------------+------------+
|    1 | name1  | 12345678901234567890123456789012 | NULL       | 1990-01-01 | 2013-01-01 |
|    2 | name2  | 12345678901234567890123456789012 | 2013-01-01 | NULL       | 2013-01-01 |
+------+--------+----------------------------------+------------+------------+------------+
2 rows in set (0.00 sec)
关于MySQL中根据生日计算年龄的SQL语句日期函数,本文就介绍这么多,希望对大家有所帮助,谢谢!

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论