gpt4 book ai didi

mysql - 使用 MySQL 将数据从一个列复制到另一个表中的另一列

转载 作者:行者123 更新时间:2023-11-29 00:10:07 24 4
gpt4 key购买 nike

我正在尝试使用 MySQL 将数据从一个列复制到另一个表中的另一列,但我要导入的表有一个外键限制,阻止我这样做;

这是我想从 (product_code) 列导入的表

表1

+----+--------------+-------------+-------+--------------+-----------+---------+-------+-------+
| id | product_code | distributor | brand | productname | wheelsize | pcd_1 | pcd_2 | pcd_3 |
+----+--------------+-------------+-------+--------------+-----------+---------+-------+-------+
| 1 | F7050MHS20A2 | ******* | MAK | MOHAVE | 7 x 15 | 5x139.7 | | |
| 2 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 3 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 4 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 5 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 6 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 7 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 8 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 9 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
| 10 | 3480 | ******* | KFZ | Winter Steel | 4.5 x 13 | 3x98 | | |
+----+--------------+-------------+-------+--------------+-----------+---------+-------+-------+

我想将 product_code 列复制到 sku

表2

+----------+----------+-------+--------------+
| id | value_id | pid | sku |
+----------+----------+-------+--------------+
| 20315857 | 369781 | 41257 | 001 |
| 20315858 | 369782 | 41256 | Config - ST5 |
+----------+----------+-------+--------------+

问题是 Table2 中的 value_id 列正在引用 value_id Table3,所以我要么得到一个外来的 key restraint error 要么 锁等待超时

 a foreign key constraint fails (`gravytra_topgear`.`am_finder_map`, CONSTRAINT `FK_MAP_VALUE` FOREIGN KEY (`value_id`) REFERENCES `am_finder_value` (`value_id`) ON D

表3

+----------+-----------+-------------+----------------+
| value_id | parent_id | dropdown_id | name |
+----------+-----------+-------------+----------------+
| 6771 | 0 | 4 | AC |
| 6749 | 0 | 4 | Acura USA |
| 6895 | 0 | 4 | Aixam |
| 6872 | 0 | 4 | Alfa Romeo |
| 6853 | 0 | 4 | Alfa Romeo USA |
| 6772 | 0 | 4 | Alpina |
| 6815 | 0 | 4 | AMC USA |
| 6854 | 0 | 4 | Anhui Anchi |
| 6928 | 0 | 4 | Ariel |
| 6783 | 0 | 4 | ARO |
+----------+-----------+-------------+----------------+

这是我的查询

INSERT INTO table2 (sku) SELECT product_code FROM table1;

table1 product_code 列中有超过 200 万条记录,导致我的服务器在查询期间崩溃。

我知道必须有更好的方法来做到这一点,但我不知道该怎么做,所以如果可能的话需要一些帮助......?

最佳答案

对我来说,你的查询看起来没问题。

尝试在 where 子句中使用一些 id 或在 select 中使用 limit 将“插入 - 选择”分成多个部分。

插入 100 条记录。看看进展如何。检查你的 time_out 变量。如果需要,相应地增加。

关于mysql - 使用 MySQL 将数据从一个列复制到另一个表中的另一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25583979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com