0

Maybe I'm just looking in the wrong corners of google but I don't understand this so if someone could explain:

I've got a table in Access that I'm inserting records into with Java ucanaccess. It has too many columns so I'm splitting up the table but the relationship between table a and b will be one to one.

I don't understand how to relate a record in the two tables during an INSERT query.

Table a has an autoincrement PK so then if I put table a PK as a foreign key in table b will it also increment automatically if they are related?

Say table a and b are as follows

//Table Pt
H_id, Age
1,        18
2,        44

//Table Imp
Imp_id, result, H_id
343,        no,   1
252,        yes,  2

And then to do the insertion in two steps (I assume)- how to I make sure that the key from the insert in table Pt can then be used as the FK in table Imp My statement (in java

 String stg = "INSERT INTO Pt (Age) VALUES('18','44')";
 qu.execute(stg);
 String stg2 = "INSERT INTO Imp (result) VALUES('no','yes')";
 qu.execute(stg2); //How do i retrieve the H_id from the first INSERT to then insert it into the second INSERT?
Sebastian Zeki
  • 6,690
  • 11
  • 60
  • 125
  • 1
    When you do the first `insert` you need get back the PK for the second `insert`, read here http://stackoverflow.com/questions/1915166/how-to-get-the-insert-id-in-jdbc – PeterMmm Apr 30 '16 at 09:31
  • 1
    First learn some SQL syntax. there are many tutorials available online. – Blip Apr 30 '16 at 09:34
  • Thanks Blip. Thats probably the most useless comment anyone's ever posted on here – Sebastian Zeki Apr 30 '16 at 09:45

0 Answers0