Received: from localhost.localdomain (unknown [202.88.224.172]) by postgresql.org (Postfix) with ESMTP id 58FD5474E61 for ; Wed, 13 Mar 2002 01:09:40 -0500 (EST) Received: from localhost (localhost [[UNIX: localhost]]) by localhost.localdomain (8.11.2/8.11.2) id g2D680X01502 for pgsql-sql@postgresql.org; Wed, 13 Mar 2002 11:38:00 +0530 Content-Type: text/plain; charset="iso-8859-1" From: Dino Cherian K Organization: ini technologies To: pgsql-sql@postgresql.org Subject: [INIMSS] How to foreign key Date: Wed, 13 Mar 2002 11:37:56 +0530 X-Mailer: KMail [version 1.2] MIME-Version: 1.0 Message-Id: <02031311263300.01381@dino> Content-Transfer-Encoding: 8bit X-Archive-Number: 200203/128 X-Sequence-Number: 7008 Hi Is there any way that I can manage the relation between two tables in some what automatic way? I have two tables A and B with primary keys pka and pkb respectively, of type serial. the pka is refered in the table B as foreign key. Its somewhat like the one given below. Table A ------------- pka | serial name | varchar(20) status | int4 Table B ------------- pka | serial pkb | int4 child | varchar(20) status | int4 Now the operator enters information to both the table from the same GUI window, so that the data relevant to table A is inserted and we take the newly got pka value by selecting ths MAX(A.pka). Then we insert the data relevant to the table B along with the new pka value. Here both the tables are exclusively locked before starting the data insertions, and later unlocked. This was the method I used in my program. Is there any other method by which we can make it in a better way? Thanks Dino Cherian K