0

My problem is that I decided to have a Test Database where I put the data I'm testing and where I can play around without any issue. When everything seems ok I migrate the data to the "official" database, where I plan to migrate different Test DBs.

The problem are child tables. I have:

Table1:          Table2:          Child:
- id             -id              -idTable1
- name           -name            -idTable2
- url            -type            -quantity

To migrate Table1 and Table2 I thought to create a temporaryID on the "official" Database. When I want to migrate the table "Child" the only thing I can think of is to check every single row and update it with the corresponding new ids. Isn't there a better way to do this?

I also thought to simply forget about Test DB and work only with the "official" one, but I am afraid of having to start again from scratch every time I make a mistake.

I think I've seen a couple of examples here on SO, but they seems much more complicated than what I need.

4

1 回答 1

0

如果问题是您不想避免 2 个(或更多)数据库上的重复 ID,您应该阅读“自动增量”和“自动增量偏移”。

如果服务器 1 有:

auto-increment-increment                        = 4
auto-increment-offset                           = 1

那么在该服务器上生成的 ID 号将是:1,5,9,13...

和第二台服务器配置为

auto-increment-increment                        = 4
auto-increment-offset                           = 2

第二台服务器上的 ID 号将是 2,6,10,14..

允许您在服务器之间复制数据,包括 ID 号

于 2012-07-06T11:24:40.343 回答