Re: finding if a foreign key is in use - Mailing list pgsql-sql

From Kenneth Gonsalves
Subject Re: finding if a foreign key is in use
Date
Msg-id 0407010743031D.02481@thenilgiris.com
Whole thread Raw
In response to Re: finding if a foreign key is in use  ("Phil Endecott" <spam_from_postgresql_sql@chezphil.org>)
Responses Re: finding if a foreign key is in use  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: finding if a foreign key is in use  (Phil Endecott <spam_from_postgresql_sql@chezphil.org>)
List pgsql-sql
On Tuesday 29 June 2004 07:19 pm, Phil Endecott wrote:
> Kenneth Gonsalves <lawgon@thenilgiris.com> 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


pgsql-sql by date:

Previous
From: "Jan Norman Pedersen"
Date:
Subject: Re: rules
Next
From: Stephan Szabo
Date:
Subject: Re: finding if a foreign key is in use