开发者

Copy 1 column to another by mysql query

开发者 https://www.devze.com 2023-03-23 02:27 出处:网络
I have mysql database with following table... id | amount | tax | +----+---开发者_如何转开发-----+-----+

I have mysql database with following table...

| id | amount | tax |
+----+---开发者_如何转开发-----+-----+
|  1 | 500    |     |
+----+--------+-----+
|  2 | 100    |     |
+----+--------+-----+

I have to delete amount column but before doing that i want to shift all data of amount row from amount row to tax row. How can it be done using mysql query? Please help.


UPDATE mytable SET tax = amount

after you can remove it

ALTER TABLE mytable DROP COLUMN amount; 


update TABLE_NAME set tax=amount;

will do.


UPDATE yTable SET tax = amount

Or to rename instead of copying (much faster):

ALTER yTable CHANGE amount tax YOURDATATYPE;

Delete tax before renaming.


update your_table_name set tax=amount

you can delete the column data

UPDATE your_table_name SET amount = NULL WHERE amount is not null;

or you can delete column itself

ALTER TABLE your_table_name DROP COLUMN amount
0

精彩评论

暂无评论...
验证码 换一张
取 消