Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id A21501337B63 for ; Tue, 30 Nov 2010 04:36:41 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 51171-02 for ; Tue, 30 Nov 2010 08:36:34 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by mail.postgresql.org (Postfix) with ESMTP id 92E5B1337B5C for ; Tue, 30 Nov 2010 04:36:32 -0400 (AST) Received: from smadev.internal.net (localhost.internal.net [127.0.0.1]) by smadev.internal.net (8.14.2/8.14.2) with ESMTP id oAU8aVoX050941 for ; Tue, 30 Nov 2010 10:36:31 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.14.2/8.14.2/Submit) id oAU8aUPu050940 for pgsql-sql@postgresql.org; Tue, 30 Nov 2010 10:36:30 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: pgsql-sql@postgresql.org Subject: Re: Deleting entries from multiple tables Date: Tue, 30 Nov 2010 11:36:29 +0300 User-Agent: KMail/1.9.7 References: <1291096741884-3285654.post@n5.nabble.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <201011301036.30047.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.671 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_BRBL_LASTEXT=1.449, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201011/87 X-Sequence-Number: 34825 Here is my take on how to regard parent tables in one-to-many FK relationsh= ips. 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=20 there is absolutely no reason for an attachment to exist when the main mess= age is gone. But, when we model e.g. machinery in a car and we have an attribute : maker= of parts modeled=20 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 i= nclude 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. =CE=A3=CF=84=CE=B9=CF=82 Tuesday 30 November 2010 10:19:04 =CE=BF/=CE=B7 Du= san Misic =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > 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. >=20 > On Tue, Nov 30, 2010 at 6:59 AM, manidegr8 wro= te: >=20 > > > > 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 > > >=20 =2D-=20 Achilleas Mantzios