Hi Folks, Quick question regarding inserting records into multiple tables that have key relationships. I have a php page that sets a variable to the nextval value, adds the record into the first table, and then inserts into the other tables with the value that was used for the first (foreign keys). Problem is, I have to add 1 onto the nextval to make this work, and when I look at the ids that are being added into the tables, they are not consecutive, one is being missed each time, so for instance I have 1000, 1002, 1004, etc. Can anyone help? Is this something to do with the way I am connecting to the database? I build it all the insertion pieces into one query separated by ";", of course. Originally I thought that was the problem, and split them into separate queries and then ran them one after the other, but no dice. Am I misunderstanding nextval? Here's how I get the nextval // Need to get value of next input id for agency_contact_info field $strnextval="SELECT nextval('agency_contact_info_id_key');"; // Open Recordset $q_nextval=pg_exec($dbconn, $strnextval) or die("Couldn't open the database --> " . pg_errormessage($q_nextval)); // Need to work out why this has to be '+1' $nextid=pg_result($q_nextval,0)+1; And here's me building the query to add in the record in the other tables // Breast Cancer Resources $strinsert_breast="INSERT INTO breast_cancer_resources (id) VALUES ($nextid);"; Thanks, much appreciated, Tom _______________________________ Tom Haddon IT Director The Better Health Foundation 414 Thirteenth Street, Suite 450 Oakland, CA 94612 (510) 444-5096 www.betterhealthfoundation.org _______________________________