Re: Deleting entries from multiple tables

Поиск
Список
Период
Сортировка
От Achilleas Mantzios
Тема Re: Deleting entries from multiple tables
Дата
Msg-id 201011301036.30047.achill@matrix.gatewaynet.com
обсуждение исходный текст
Ответ на Re: Deleting entries from multiple tables  (Dusan Misic <promisic@gmail.com>)
Список pgsql-sql
Here is my take on how to regard parent tables in one-to-many FK relationships.
If lets say we have a situation when we model e.g. mail messages and its
attachments, then we might want to use ON DELETE CASCADE since
there is absolutely no reason for an attachment to exist when the main message is gone.
But, when we model e.g. machinery in a car and we have an attribute : maker of parts modeled
as a parent table and the child parts table pointing to this maker table,
then this parent table is not of high significance and we should not put ON DELETE CASCADE.
In this way, we protect the database of deleting vital data.

Note that under the parts table, other tables might point to, which would include history,
plan maintenace, and other very vital data.

So, you are enouraged to put ON DELETE CASCADE ONLY when you are confident that the child table's rows
have absolutely no meaning without the parent table row.
Otherwise, leave the default behaviour.

Στις Tuesday 30 November 2010 10:19:04 ο/η Dusan Misic έγραψε:
> To be precise, if you used defaults, you can't delete any row in table A
> that has rows referencing to it in tables B and C.
>
> On Tue, Nov 30, 2010 at 6:59 AM, manidegr8 <engineer.usman@ymail.com> wrote:
>
> >
> > i am trying to run a query but its not working may be due to constraint
> > conflicts
> >
> > i have table A, B and C
> > B and C have a foreign key linked with A's primary key
> >
> > so i want to delete an entry from A
> > for that i hav to delete child records first
> >
> > can u design a query which wont conflict the constraints..?
> >
> > Thanks...
> > Regards.
> > --
> > View this message in context:
> > http://postgresql.1045698.n5.nabble.com/Deleting-entries-from-multiple-tables-tp3285654p3285654.html
> > Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
> >
> > --
> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-sql
> >
>



--
Achilleas Mantzios


В списке pgsql-sql по дате отправления:

Предыдущее
От: Dusan Misic
Дата:
Сообщение: Re: Deleting entries from multiple tables
Следующее
От: Carla
Дата:
Сообщение: Re: subselect and left join not working?