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

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: PostreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How can I delete a primary or foreign key?
Date: 2004-06-05 23:32:03
Message-ID: 200406051632.03143.aklaver@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I got it to work by using the form:
ALTER TABLE tablename DROP CONSTRAINT constraint name;
No reference to FOREIGN KEY, just use the constraint name.
On Friday 20 February 2004 08:04 am, 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;
>
> but all I got was:
>
> ERROR: syntax error at or near "foreign" at character 37
>
> the DROP CONSTRAINT clause doesn't recognise either PRIMARY or FOREIGN KEY
> option. (not implemented, I guess)
>
> On Friday 20 Feb 2004 16:42, you wrote:
> > On Fri, 20 Feb 2004, Tibor wrote:
> > > I am using PostgreSQL 7.4.1 (only through psql)
> > > I know, that the command
> > >
> > > ALTER TABLE OFFICES
> > > DROP PRIMARY KEY (CITY);
> > >
> > > and its foreign key equivalent:
> > >
> > > ALTER TABLE SALESREPS
> > > DROP CONSTRAINT
> > > FOREIGN KEY (REP_OFFICE)
> > > REFERENCES OFFICES;
> > >
> > > don't work in PostgreSQL because they are not implemented. However,
> > > isn't there another way of removing them?
> >
> > That's not the correct syntax for ALTER TABLE ... DROP CONSTRAINT.
> >
> > ALTER TABLE tablename DROP CONSTRAINT constraint_name [RESTRICT |
> > CASCADE]

--
Adrian Klaver
aklaver(at)comcast(dot)net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-06-06 00:15:54 Re: Why hash indexes suck
Previous Message Greg Stark 2004-06-05 23:03:08 Re: How to find out who is calling the function