在两个新表中将表合并为一个具有相同生成数的表

时间:2012-10-14 19:13:33

标签: mysql sql database

我找到了运行mysql查询以将一个表迁移/拆分为2个新表的一些选项,但我想在新表上创建的一个字段必须与另一个新表中的字段相同:< / p>

所以从“From_payments”表中,我想创建两个名为“To_paymenttransaction”和“To_paymentinfo”的新表。该字段的lof是预定义的,一些来自旧表。唯一的问题是预定义字段“paymentinfoid”必须与新表相同。

**To_paymenttransaction** --- < --- **From_payments**

paymenttransactionid ------- < --- (Generate next available number in this column)

paymentinfoid -------------- < --- (Generate next available number in this column)

transactionid --------------- < --- txn_id

state ---------------------- < --- (Set all to "1")

amount -------------------- < --- mc_gross

currency ------------------- < --- mc_currency

dateline -------------------- < --- payment_date

paymentapiid --------------- < --- (Set all to "1")

request -------------------- < --- (Set all to "NULL")

reversed ------------------- < --- (Set all to "0")

**To_paymentinfo** -----------< 

paymentinfoid -------------- < --- (Same generated number that goes to the paymentinfoif field in To_paymenttransaction table )

hash ----------------------- < --- (Set all to "Imported")

subscriptionid --------------- < --- (Set all to "1")

subscriptionsubid ------------ < --- ("2" IF above field mc_gross is 4, "1" IF above field mc_gross is 6, "0" IF above field mc_gross is 10)

userid   ---------------------- < --- userid

completed ------------------ < --- (Set all to "0")

有什么想法吗?

非常感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

在分割之前,可能会在原始表上生成paymentinfoid。然后,您可以将该单个条目复制到每个新表中。