posted 18 years ago
Hello ranch members,
I have the following scenario and would like suggestions on the best possible design for it.
TableA (id_A, blah1, blah2)
TableB (id_B, id_A)
I am using MySQL and id_A and id_B are primary keys for the respective tables. I am generating values for keys using AUTO_INCREMENT in MySQL.
I have a single DAO class and want to insert data into both these tables using it.
My problem is how would I insert a value for id_A in TableB.
The only way I could think of is was that insert values in TableA and the query the newly inserted record, use this id for TableB.
There are two problems with above approach one an extra select query and second since I am auto generating the key values I do not know the value of id_A for the newly created record.
Any suggestions are appreciated.
Thanks,
Manhar.