Re: [GENERAL] Foreign Keys Help Delete!

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: [GENERAL] Foreign Keys Help Delete!
Дата
Msg-id 39C7FFFB.6A9A0A2B@agliodbs.com
обсуждение исходный текст
Ответ на [GENERAL] Foreign Keys Help Delete!  (Timothy Covell <dirac@applink.net>)
Список 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 по дате отправления:

Предыдущее
От: Timothy Covell
Дата:
Сообщение: [GENERAL] Foreign Keys Help Delete!
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: [GENERAL] Foreign Keys Help Delete!