Heim  >  Artikel  >  Datenbank  >  MySQL命令行删除表中的一个字段_MySQL

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

PHP中文网
PHP中文网Original
2016-05-27 13:44:371779Durchsuche

先看看删除之前的表结构:

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

a26d98d33123a70024fa8ba5642906c6 drop column 7d7db3eee304faccc5db90e2b256afeb;

具体的命令如下:

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命令行删除表中的一个字段_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn