我具有表A(與AI PK)一組行的,我想基於特定標準來克隆,即:MySQL的:在表克隆在表A中的多個行和相關行乙
INSERT INTO A(field1,field2,field3)SELECT field1,field2,field3 FROM A WHERE(criteria)
但是,這些行與Table B有1-1的關係,它們在B中具有AI PK,在A中具有FK。我還想克隆表B中的相關行,並將A中的克隆行指向B中的克隆行而不是原始行。
我正在尋找最簡單的方法來做到這一點 - 最好只是在SQL中。
這裏是什麼,我試圖做一個例子:
前CLONE:
Table A
ID B_FK Other Data Meets Clone Criteria
1 101 Data 1 true
2 102 Data 2 false
3 103 Data 3 true
4 104 Data 4 true
Table B
ID Other Data
101 Data A
102 Data B
103 Data C
104 Data D
AFTER行CLONING:
Table A
ID B_FK Other Data
1 101 Data 1
2 102 Data 2
3 103 Data 3
4 104 Data 4
5 105 Data 1
6 106 Data 3
7 107 Data 4
Table B
ID Other Data
101 Data A
102 Data B
103 Data C
104 Data D
105 Data A
106 Data C
107 Data D
這個問題解決了在SQL Server中同樣的問題 - 但我被堵在MySQL:http://stackoverflow.com/questions/5365629/using-merge-output-to-get- mapping-between-source-id-and-target-id – scotru
下面是一個與存儲相關的問題過程做單行 - 但我想做一整行的行:http://stackoverflow.com/questions/6767066/copy-row-and-all-of-its-children – scotru