Skip site navigation (1) Skip section navigation (2)

Re: Changing primary keys

From: "Brandon Aiken" <BAiken(at)winemantech(dot)com>
To: "Carol Cheung" <cacheung(at)consumercontact(dot)com>,<pgsql-novice(at)postgresql(dot)org>
Subject: Re: Changing primary keys
Date: 2006-09-27 20:14:22
Message-ID: F8E84F0F56445B4CB39E019EF67DACBA3408E9@exchsrvr.winemantech.com (view raw or flat)
Thread:
Lists: pgsql-novice
First, you'll have to describe the table or fire up pgAdmin to get the
constraint's name.  The default is usually "tablename_pkey".

ALTER TABLE "house" DROP CONSTRAINT "house_pkey";
ALTER TABLE "house" ADD CONSTRAINT "house_pkey" PRIMARY KEY
("house_id");

Beware: PostgreSQL will yell at you if the new key has duplicates and
will not create the constraint.  PostgreSQL will also probably yell at
you if you try to drop a constraint which is the target of a foreign key
constraint in another table.

--
Brandon Aiken
CS/IT Systems Engineer
-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Carol Cheung
Sent: Wednesday, September 27, 2006 3:55 PM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] Changing primary keys

Hi,

The table 'house' was created with the below code (partial)

CREATE TABLE house (
   house_id bigserial unique not null,
   phone bigint not null,
   address varchar(75) not null,
   primary key(phone, address)
);

My question is how can I switch the primary key from (phone, address) to

house_id, now that the table is created and records have been inserted.

Thanks,
C

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

In response to

pgsql-novice by date

Next:From: Ray StellDate: 2006-09-27 21:06:57
Subject: tablespace?
Previous:From: Richard Broersma JrDate: 2006-09-27 20:04:52
Subject: Re: Changing primary keys

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group