MySQL command line deletes a field in the table, mysql Command Line Field
Let's take a look at the table structure before deletion:
Mysql> select * from test;
+ ------ + -------- + -------------------------------- + ------------ + -------------- + ------------ +
| T_id | t_name | t_password | t_birth | birth | birth1 | bir22. |
+ ------ + -------- + -------------------------------- + ------------ + -------------- + ------------ +
| 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)
Run the DELETE command and use the drop keyword.
The basic syntax is: alter table <table Name> drop column <field Name>;
The specific command is as follows:
Mysql> alter table test drop column birth1;
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0
Check the deleted result. Is there no birth1 field?
Mysql> select * from test;
+ ------ + -------- + ---------------------------------- + ------------ +
| T_id | t_name | t_password | t_birth | birth | bir22. |
+ ------ + -------- + ---------------------------------- + ------------ +
| 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)
This article describes the date functions of SQL statements used to calculate the age based on the birthday in MySQL. I hope this will help you. Thank you!