"be consistent" | |
PerlMonks |
SQL question: Insertion with FK constraintby lihao (Monk) |
on Jun 26, 2008 at 14:45 UTC ( [id://694170]=perlquestion: print w/replies, xml ) | Need Help?? |
lihao has asked for the wisdom of the Perl Monks concerning the following question:
Hope it's not over OT. I have several MySQL tables connected/constraint by Foreign Keys, for example:
When updating `table1`, I need to check `table2` and see if the given `property` exists, if it exists, return its `id` to table1.property_id; otherwise, insert it into table2 and return last_insert_id() to table1.property_id. Currently I am using DBIx::Simple, so I do it the following way (sample code):
Since there are many places(tables and columns) in my DB that need to be updated under the FK constraints. My question is: Are there simpler ways to handle this situation nicely without using the above code? many thanks lihao
Back to
Seekers of Perl Wisdom
|
|