我有一个带有以下表的mysql数据库...
| id | amount | tax |
+----+--------+-----+
| 1 | 500 | |
+----+--------+-----+
| 2 | 100 | |
+----+--------+-----+
我需要删除 amount 列,但在这样做之前,我想将 amount 行中的所有数据移动到 tax 行。如何使用 MySQL 查询完成?请帮忙。
我有一个带有以下表的mysql数据库...
| id | amount | tax |
+----+--------+-----+
| 1 | 500 | |
+----+--------+-----+
| 2 | 100 | |
+----+--------+-----+
我需要删除 amount 列,但在这样做之前,我想将 amount 行中的所有数据移动到 tax 行。如何使用 MySQL 查询完成?请帮忙。
UPDATE mytable SET tax = amount
之后你可以将它移除
ALTER TABLE mytable DROP COLUMN amount;
update TABLE_NAME set tax=amount;
will do.
UPDATE yTable SET tax = amount
或者重命名而不是复制(速度更快):
ALTER yTable CHANGE amount tax YOURDATATYPE;
在重命名之前删除税。
update your_table_name set tax=amount
你可以删除列数据
UPDATE your_table_name SET amount = NULL WHERE amount is not null;
ALTER TABLE your_table_name DROP COLUMN amount