X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C8031D1B386 for ; Thu, 1 Jul 2004 00:50:25 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57273-04 for ; Thu, 1 Jul 2004 03:50:17 +0000 (GMT) Received: from sharp.noc24x7.com (unknown [69.56.128.138]) by svr1.postgresql.org (Postfix) with ESMTP id 0F0B7D1B37D for ; Thu, 1 Jul 2004 00:50:15 -0300 (ADT) Received: from [61.1.218.164] (helo=thenilgiris.com) by sharp.noc24x7.com with asmtp (Exim 4.34) id 1BfsaU-0003lt-8p; Thu, 01 Jul 2004 09:20:15 +0530 Received: from localhost (localhost [[UNIX: localhost]]) by thenilgiris.com (8.11.2/8.11.2) id i612D4J13955; Thu, 1 Jul 2004 07:43:04 +0530 Content-Type: text/plain; charset="iso-8859-1" From: Kenneth Gonsalves To: "Phil Endecott" , Subject: Re: finding if a foreign key is in use Date: Thu, 1 Jul 2004 07:43:03 +0530 X-Mailer: KMail [version 1.2] References: <0406290618410W.02481@thenilgiris.com> <7679232@chezphil.org> In-Reply-To: <7679232@chezphil.org> MIME-Version: 1.0 Message-Id: <0407010743031D.02481@thenilgiris.com> Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sharp.noc24x7.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - thenilgiris.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/2 X-Sequence-Number: 18254 On Tuesday 29 June 2004 07:19 pm, Phil Endecott wrote: > Kenneth Gonsalves wrote: > > in my app i have a table where the id serves as a foreign key for > > one or more other tables. if i want to delete a row in the table, > > i currently search the other tables where this table is referenced > > to see if the row is in use - and then, if not in use, permit > > deletion. > > Now if i want the delete button in my app to be disabled whenever > > a row that is in use is selected, searching the database every time > > would dramatically slow down the app. > > Basically you do have to do this search. But it won't be too slow if you > create an index on the foreign key. pity. thought postgres would have some function like 'in_use' to tell when a row that is used as a foreign key is in actual use and hence cannot be deleted. surely, in a database of millions of records, it wouldnt have search them all to find if the row is in use? in my case the id field serves as a foreign key in several tables -- regards kg http://www.onlineindianhotels.net - hotel bookings reservations in over 4600 hotels in India http://www.ootygolfclub.org