mysql - Is it good practice to keep 2 related tables (using auto_increment PK) to have the same Max of auto_increment ID when table1 got modified? -


let see example, have 2 interrelated tables:

 table1 textid - text 1      - love.. 2      - men... ...  table2 rid - textid 1   - 1 2   - 2 ... 

note:

in table1:

  • textid auto_increment primary key

in table2:

  • rid auto_increment primary key & textid foreign key

  • the relationship 1 rid have 1 , 1 textid 1 textid can have few rid.

so, when table1 got modification table2 should updated accordingly.

ok, here fictitious example. build complicated system. when modify 1 record in table1, need keep track of related record in table2. keep track, can this:

option 1: when modify record in table1, try modify related record in table 2. quite hard in term of programming expecially very complicated system.

option 2: instead of modifying related record in table2, decided delete old record in table 2 & insert new one. easier program.

for example, suppose using option2, when modify record 1,2,3,....,100 in table1, table2 this:

 table2 rid   - textid 101   - 1 102   - 2 ... 200   - 100 

this means max of auto_increment ids in table1 still same (100) max of auto_increment ids in table2 reached 200.

what if user modify many times? if table2 may run out of records? can use bigint make app run slower?

note: if spend time program modify records in table2 when table1 got modified hard & error prone. if clear old record & insert new records table2 easy program & program simpler & less error prone.

so, practice keep 2 related tables (using auto_increment pk) have same max of auto_increment id when table1 got modified?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -