Re: How can I delete a primary or foreign key?

From: tibor <tiborh(at)mail(dot)datanet(dot)hu>
To: PostreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How can I delete a primary or foreign key?
Date: 2004-02-20 17:06:44
Message-ID: 200402201806.44753@newid
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday 20 Feb 2004 18:00, you wrote:
> On Fri, 20 Feb 2004, tibor wrote:
> > I forgot to mention that I have tried numerous variations.
> > The one quoted in the original mail was from "The Complete Reference"
> > series. I've also tried the one that the \h command suggests:
> >
> > ALTER TABLE PARENTS DROP CONSTRAINT FOREIGN KEY (TYPE) CASCADE;
>
> \h shows me
> ALTER TABLE [ ONLY ] name [ * ]
> DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ]
>
> constraint_name isn't something like: FOREIGN KEY ...
> it's the name given to the constraint (preferably at add time with the
> CONSTRAINT constraint_name clause otherwise it's given an arbitrary name).
>

You are perfectly right. I simply forgot to put in the name of the constraint.

> If you use \d tablename
> You should see something like:
> Foreign-key constraints:
> "$1" FOREIGN KEY (b) REFERENCES a(a)
>
> And the drop would look like
> ALTER TABLE tablename DROP CONSTRAINT "$1";

Thank you for your help and the info!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2004-02-20 17:08:22 Re: How can I delete a primary or foreign key?
Previous Message tibor 2004-02-20 17:03:12 Re: How can I delete a primary or foreign key?