在MySQL表中复制一行

时间:2022-09-16 10:04:32

I have a table with rows [Item_name varchar(255) Primary key] and [Price varchar(255)], and a few others. I want to copy the row price into the same table, with a new name "old_price". How do I do this? I did some research and tried this:

我有一个表有行[Item_name varchar(255)主键]和[Price varchar(255)],以及其他一些表。我想将行价复制到同一个表中,使用新名称“old_price”。我该怎么做呢?我做了一些研究并尝试了这个:

INSERT INTO item_list (item_list.price) (SELECT item_list.price FROM item_list WHERE item_name = item_name);

I get the error "Field 'Item_name' doesn't have a default value"

我收到错误“字段'Item_name'没有默认值”

1 个解决方案

#1


UPDATE  item_list  SET old_price=price ;

first update the table with column name old_price.

首先使用列名old_price更新表。

#1


UPDATE  item_list  SET old_price=price ;

first update the table with column name old_price.

首先使用列名old_price更新表。