X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 38C49CC23A for ; Tue, 15 Jul 2003 04:48:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 48135-02 for ; Tue, 15 Jul 2003 04:48:20 +0000 (GMT) Received: from megazone.bigpanda.com (unknown [66.180.233.26]) by svr1.postgresql.org (Postfix) with ESMTP id BE6BCCC289 for ; Tue, 15 Jul 2003 01:47:52 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 12D28D614; Mon, 14 Jul 2003 21:48:19 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 0874C5C0C; Mon, 14 Jul 2003 21:48:18 -0700 (PDT) Date: Mon, 14 Jul 2003 21:48:18 -0700 (PDT) From: Stephan Szabo To: Matt Tenenbaum Cc: Subject: Re: ad hoc referential integrity In-Reply-To: <606FC028-B67E-11D7-BFF3-0003939515A2@tty1.org> Message-ID: <20030714214641.B79686-100000@megazone.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/160 X-Sequence-Number: 14274 On Tue, 15 Jul 2003, Matt Tenenbaum wrote: > Say I created a couple tables A and B, where A contains a column p > which B references as a foreign key. Further say that, when I created > these tables, I meant to specify 'on delete cascade' for p in the > definition of B but didn't. What's the proper way to ensure both the > integrity of the tables and that, when I delete rows from A, the > corresponding rows from B are removed as well? (In particular, is there > a shorter way than dropping the table and recreating it? Are rules the > answer?) If I'm understanding what you want, I'd suggest dropping the constraint and re-adding it with the on delete cascade. If you're on 7.3 or better you should be able to do this entirely with alter table, before that you have to do a little more work.