Re: [GENERAL] Foreign Keys Help Delete! - Mailing list pgsql-sql

From Josh Berkus
Subject Re: [GENERAL] Foreign Keys Help Delete!
Date
Msg-id 39C7FFFB.6A9A0A2B@agliodbs.com
Whole thread Raw
In response to [GENERAL] Foreign Keys Help Delete!  (Timothy Covell <dirac@applink.net>)
List pgsql-sql
Mr. Covell,

> 2. When I try to update "routes" table, it updates.

Actually, what I'm curious about is this part.  Most databases that
support foriegn keys will not allow you to modify them as long as a
relation exists referencing the key, on either the master or child side,
unless you are updating the child to NULL (if the column is nullable) or
a valid alternative forign key value.

If you have updated the child record so that no records reference the
master key value, that key value should be then updatable without
violating the Forign Key constraint.  However, I have not had reason to
test this on 7.0.2.

This provides you with two approaches for updating BOTH hosts and routes
table:

1. a. Create new record with new key value in hosts table with the
desired value  b. Update the routes record to reference the new value  c. Delete the old record in the hosts table

2. a. Drop the Foriegn Key constraint  b. Update both the routes and hosts tables  c. Re-establish the foriegn key
constraint

If either of these approaches doesn't work, you have a valid bug
report.  COngratulations!

-Josh Berkus


-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 436-9166  for law firms, small
businesses      fax  436-0137   and non-profit organizations.       pager 338-4078                               San
Francisco


pgsql-sql by date:

Previous
From: Timothy Covell
Date:
Subject: [GENERAL] Foreign Keys Help Delete!
Next
From: Stephan Szabo
Date:
Subject: Re: [GENERAL] Foreign Keys Help Delete!