【发布时间】:2016-08-11 17:35:13
【问题描述】:
假设我有 3 个表,每个表的结构类似于:
| id | customer_id | col1 | col2 | col3 |
|----|-------------|------------|------------|-------------|
| 1 | C100 | some value | some value | some values |
| 2 | C101 | | | |
| 3 | C102 | | | |
现在我想用特定的customer-id 复制它们的行。
所以在伪代码中类似于:
DUPLICATE FROM tab1, tab2, tab3 WHERE customer_ID = C100 SET customer_ID = C987;
它将采用customer_id 为C100 的那三个表的值,并在每个表中创建另一个条目,但使用新的customer_id C987。
这 3 个表如下所示:
| id | customer_id | col1 | col2 | col3 |
|----|-------------|------------|------------|-------------|
| 1 | C100 | some value | some value | some values |
| 2 | C101 | | | |
| 3 | C102 | | | |
| 4 | C987 | some value | some value | some value |
此外,表中的结构也略有不同。
id 是主键,customer_id 是唯一的。
【问题讨论】:
-
所以你要换行吗?您的示例中没有 customer_id =123 的行。表上是否有任何唯一索引?你的意思是“3 个表”还是“3 行”?
-
@dan08 对不起,我的错。我换了身份证。是的,id 和 customer-ID 都是唯一的。
-
有几个表,在我的示例中我将其更改为 3。所以是的,我的意思是 3 个表。它们每个都有不同的结构。