Re: Adding a Primary Key to an exisiting table - Mailing list pgsql-sql

From Bhuvan A
Subject Re: Adding a Primary Key to an exisiting table
Date
Msg-id Pine.LNX.4.44.0301031046090.1186-100000@Bhuvan.bksys.co.in
Whole thread Raw
In response to Adding a Primary Key to an exisiting table  (Maly Kaing <mkaing1@gl.umbc.edu>)
List pgsql-sql
> Hi
> 
> I just exported my MS Access databases into postgres using an ODBC driver,
> but the thing is during the export postgres doesn't recognize any of my
> primary keys in Access.
> Is there any way to alter the tables so that i can make one of my current
> fields the primary key?  I don't want to drop the column since I already
> have data in the table and i don't want to create/drop tables as some of
> the documentation suggests since most of my tables have 10+ fields.. any
> suggestions??
> 

AFAIK, it can be done in any of the below two ways:

1. Create unique index  CREATE UNIQUE INDEX index_name ON table_name USING btree (field1, ..,   fieldn);
2. Add primary key constraint  ALTER TABLE table_name ADD PRIMARY KEY (field1, .., fieldn);

For this to happen, the fields should have unique values.

regards,
bhuvaneswaran




pgsql-sql by date:

Previous
From: "Brian Walker"
Date:
Subject: NULLL comparison in multiple column unique index
Next
From: Manfred Koizar
Date:
Subject: Re: NULLL comparison in multiple column unique index