php - MySQL tricky multiple row insert/update into two tables -
there 2 tables following columns:
table1 (id1, id2)  //pairs (id1, id2) - unique  table2 (id2, name) //id2 - auto incrementing, name - string    from php have 100-300 pairs (id1, name) have inserted tables following conditions:
- some (id1, id2) pairs can not yet in table1, 'name' in table2. in case table1 has filled corresponding id1, id2.
 - if (id1, id2) pair in table1 - 'name' in table2 has updated, if not same.
 
how accomplish performance in mind?
ps: can not use foreign keys or fuse tables
edit: here example, demonstrate logic
given 100-300 pairs of (id1,name):
id1   |  name --------------  5    |  name0 10    |  name1 20    |  name2 30    |  xxxxx   tables table1 , table2 either empty or contain records:
table1:                 table2: id1   |  id2            id2   |  name --------------          ----------------  5    |  0              0     |  name0       |                 1     |  name1 30    |  2              2     |  yyyyy   after insertion of given pairs tables should contain:
table1:                 table2: id1   |  id2            id2   |  name --------------          ----------------  5    |  0              0     |  name0      <-not touched 10    |  1              1     |  name1      <-table1 updated 30    |  2              2     |  xxxxx      <-changed name 20    |  3              3     |  name2      <-inserted both tables       
 
Comments
Post a Comment